Skip to content

Commit 7810b2e

Browse files
committed
Address const-correctness flagged by clang-tidy (including some spurious situations).
1 parent ff395d1 commit 7810b2e

File tree

7 files changed

+71
-23
lines changed

7 files changed

+71
-23
lines changed

src/core/integer.cc

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ static void Icheck(IntegerRep *rep)
147147

148148
static void Iclear_from(IntegerRep *rep, int p)
149149
{
150+
// NOLINTBEGIN(misc-const-correctness)
150151
unsigned short *cp = &(rep->s[p]);
152+
// NOLINTEND(misc-const-correctness)
151153
const unsigned short *cf = &(rep->s[rep->len]);
152154
while (cp < cf) {
153155
*cp++ = 0;
@@ -723,7 +725,9 @@ IntegerRep *add(const IntegerRep *x, int negatex, const IntegerRep *y, int negat
723725
else {
724726
r = Icalloc(r, calc_len(xl, yl, 0));
725727
}
728+
// NOLINTBEGIN(misc-const-correctness)
726729
unsigned short *rs = r->s;
730+
// NOLINTEND(misc-const-correctness)
727731
const unsigned short *as;
728732
const unsigned short *bs;
729733
const unsigned short *topa;
@@ -834,7 +838,9 @@ IntegerRep *add(const IntegerRep *x, int negatex, long y, IntegerRep *r)
834838
else {
835839
r = Icalloc(r, calc_len(xl, yl, 0));
836840
}
841+
// NOLINTBEGIN(misc-const-correctness)
837842
unsigned short *rs = r->s;
843+
// NOLINTEND(misc-const-correctness)
838844
const unsigned short *as;
839845
const unsigned short *bs;
840846
const unsigned short *topa;
@@ -904,7 +910,9 @@ IntegerRep *multiply(const IntegerRep *x, const IntegerRep *y, IntegerRep *r)
904910
r = Icalloc(r, rl);
905911
}
906912
unsigned short *rs = r->s;
913+
// NOLINTBEGIN(misc-const-correctness)
907914
unsigned short *topr = &(rs[rl]);
915+
// NOLINTEND(misc-const-correctness)
908916

909917
// use best inner/outer loop params given constraints
910918
unsigned short *currentr;
@@ -965,7 +973,9 @@ IntegerRep *multiply(const IntegerRep *x, const IntegerRep *y, IntegerRep *r)
965973
{
966974
r = Iresize(r, rl);
967975
unsigned short *botr = r->s;
976+
// NOLINTBEGIN(misc-const-correctness)
968977
unsigned short *topr = &(botr[rl]);
978+
// NOLINTEND(misc-const-correctness)
969979
unsigned short *rs = &(botr[rl - 2]);
970980

971981
const unsigned short *bota = (xrsame) ? botr : x->s;
@@ -979,7 +989,9 @@ IntegerRep *multiply(const IntegerRep *x, const IntegerRep *y, IntegerRep *r)
979989
*rs = 0;
980990

981991
for (;;) {
992+
// NOLINTBEGIN(misc-const-correctness)
982993
unsigned short *rt = rs;
994+
// NOLINTEND(misc-const-correctness)
983995
unsigned long sum = prod + (unsigned long)(*rt);
984996
*rt++ = extract(sum);
985997
sum = down(sum);
@@ -1054,7 +1066,9 @@ IntegerRep *multiply(const IntegerRep *x, long y, IntegerRep *r)
10541066
}
10551067

10561068
unsigned short *rs = r->s;
1069+
// NOLINTBEGIN(misc-const-correctness)
10571070
unsigned short *topr = &(rs[rl]);
1071+
// NOLINTEND(misc-const-correctness)
10581072
unsigned short *currentr;
10591073
const unsigned short *bota;
10601074
const unsigned short *as;
@@ -1191,7 +1205,9 @@ static int unscale(const unsigned short *x, int xl, unsigned short y, unsigned s
11911205
}
11921206
else if (q != nullptr) {
11931207
unsigned short *botq = q;
1208+
// NOLINTBEGIN(misc-const-correctness)
11941209
unsigned short *qs = &(botq[xl - 1]);
1210+
// NOLINTEND(misc-const-correctness)
11951211
const unsigned short *xs = &(x[xl - 1]);
11961212
unsigned long rem = 0;
11971213
while (qs >= botq) {
@@ -1646,7 +1662,9 @@ IntegerRep *lshift(const IntegerRep *x, long y, IntegerRep *r)
16461662
}
16471663

16481664
unsigned short *botr = r->s;
1665+
// NOLINTBEGIN(misc-const-correctness)
16491666
unsigned short *rs = &(botr[rl - 1]);
1667+
// NOLINTEND(misc-const-correctness)
16501668
const unsigned short *botx = (xrsame) ? botr : x->s;
16511669
const unsigned short *xs = &(botx[xl - 1]);
16521670
unsigned long a = 0;
@@ -1673,7 +1691,9 @@ IntegerRep *lshift(const IntegerRep *x, long y, IntegerRep *r)
16731691
}
16741692
const int rw = I_SHIFT - sw;
16751693
unsigned short *rs = r->s;
1694+
// NOLINTBEGIN(misc-const-correctness)
16761695
unsigned short *topr = &(rs[rl]);
1696+
// NOLINTEND(misc-const-correctness)
16771697
const unsigned short *botx = (xrsame) ? rs : x->s;
16781698
const unsigned short *xs = &(botx[bw]);
16791699
const unsigned short *topx = &(botx[xl]);
@@ -1724,7 +1744,9 @@ IntegerRep *bitop(const IntegerRep *x, const IntegerRep *y, IntegerRep *r, char
17241744
}
17251745
r->sgn = xsgn;
17261746
unsigned short *rs = r->s;
1747+
// NOLINTBEGIN(misc-const-correctness)
17271748
unsigned short *topr = &(rs[r->len]);
1749+
// NOLINTEND(misc-const-correctness)
17281750
const unsigned short *as;
17291751
const unsigned short *bs;
17301752
const unsigned short *topb;
@@ -1800,7 +1822,9 @@ IntegerRep *bitop(const IntegerRep *x, long y, IntegerRep *r, char op)
18001822
}
18011823
r->sgn = xsgn;
18021824
unsigned short *rs = r->s;
1825+
// NOLINTBEGIN(misc-const-correctness)
18031826
unsigned short *topr = &(rs[r->len]);
1827+
// NOLINTEND(misc-const-correctness)
18041828
const unsigned short *as;
18051829
const unsigned short *bs;
18061830
const unsigned short *topb;
@@ -1850,7 +1874,9 @@ IntegerRep *Compl(const IntegerRep *src, IntegerRep *r)
18501874
nonnil(src);
18511875
r = Icopy(r, src);
18521876
unsigned short *s = r->s;
1877+
// NOLINTBEGIN(misc-const-correctness)
18531878
unsigned short *top = &(s[r->len - 1]);
1879+
// NOLINTEND(misc-const-correctness)
18541880
while (s < top) {
18551881
const unsigned short cmp = ~(*s);
18561882
*s++ = cmp;
@@ -2240,7 +2266,9 @@ std::string cvtItoa(const IntegerRep *x, std::string fmt, int &fmtlen, int base,
22402266
int width, int align_right, char fillchar, char Xcase, int showpos)
22412267
{
22422268
char *e = const_cast<char *>(fmt.c_str()) + fmtlen - 1;
2269+
// NOLINTBEGIN(misc-const-correctness)
22432270
char *s = e;
2271+
// NOLINTEND(misc-const-correctness)
22442272
*--s = 0;
22452273

22462274
if (x->len == 0) {
@@ -2323,7 +2351,7 @@ std::string cvtItoa(const IntegerRep *x, std::string fmt, int &fmtlen, int base,
23232351
#ifdef UNUSED
23242352
int gap = (int)(s - p);
23252353
#endif // UNUSED
2326-
for (char *t = s; *t != 0; ++t, ++p) {
2354+
for (const char *t = s; *t != 0; ++t, ++p) {
23272355
*p = *t;
23282356
}
23292357
while (w++ < width) {

src/core/matrix.imp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ template <class T> Matrix<T> Matrix<T>::operator+(const Matrix<T> &M) const
8888

8989
const Matrix<T> tmp(this->minrow, this->maxrow, this->mincol, this->maxcol);
9090
for (int i = this->minrow; i <= this->maxrow; i++) {
91-
T *src1 = this->data[i] + this->mincol;
92-
T *src2 = M.data[i] + this->mincol;
91+
const T *src1 = this->data[i] + this->mincol;
92+
const T *src2 = M.data[i] + this->mincol;
93+
// NOLINTBEGIN(misc-const-correctness)
9394
T *dst = tmp.data[i] + this->mincol;
95+
// NOLINTEND(misc-const-correctness)
9496
int j = this->maxcol - this->mincol + 1;
9597
while (j--) {
9698
*(dst++) = *(src1++) + *(src2++);
@@ -108,9 +110,11 @@ template <class T> Matrix<T> Matrix<T>::operator-(const Matrix<T> &M) const
108110

109111
const Matrix<T> tmp(this->minrow, this->maxrow, this->mincol, this->maxcol);
110112
for (int i = this->minrow; i <= this->maxrow; i++) {
111-
T *src1 = this->data[i] + this->mincol;
112-
T *src2 = M.data[i] + this->mincol;
113+
const T *src1 = this->data[i] + this->mincol;
114+
const T *src2 = M.data[i] + this->mincol;
115+
// NOLINTBEGIN(misc-const-correctness)
113116
T *dst = tmp.data[i] + this->mincol;
117+
// NOLINTEND(misc-const-correctness)
114118
int j = this->maxcol - this->mincol + 1;
115119
while (j--) {
116120
*(dst++) = *(src1++) - *(src2++);
@@ -127,8 +131,10 @@ template <class T> Matrix<T> &Matrix<T>::operator+=(const Matrix<T> &M)
127131
}
128132

129133
for (int i = this->minrow; i <= this->maxrow; i++) {
130-
T *src = M.data[i] + this->mincol;
134+
const T *src = M.data[i] + this->mincol;
135+
// NOLINTBEGIN(misc-const-correctness)
131136
T *dst = this->data[i] + this->mincol;
137+
// NOLINTEND(misc-const-correctness)
132138
int j = this->maxcol - this->mincol + 1;
133139
while (j--) {
134140
*(dst++) += *(src++);
@@ -144,8 +150,10 @@ template <class T> Matrix<T> &Matrix<T>::operator-=(const Matrix<T> &M)
144150
}
145151

146152
for (int i = this->minrow; i <= this->maxrow; i++) {
147-
T *src = M.data[i] + this->mincol;
153+
const T *src = M.data[i] + this->mincol;
154+
// NOLINTBEGIN(misc-const-correctness)
148155
T *dst = this->data[i] + this->mincol;
156+
// NOLINTEND(misc-const-correctness)
149157
int j = this->maxcol - this->mincol + 1;
150158
while (j--) {
151159
*(dst++) -= *(src++);
@@ -168,7 +176,7 @@ template <class T> void Matrix<T>::CMultiply(const Vector<T> &in, Vector<T> &out
168176
for (int i = this->minrow; i <= this->maxrow; i++) {
169177
T sum = (T)0;
170178

171-
T *src1 = this->data[i] + this->mincol;
179+
const T *src1 = this->data[i] + this->mincol;
172180
auto src2 = in.begin();
173181
int j = this->maxcol - this->mincol + 1;
174182
while (j--) {
@@ -216,7 +224,7 @@ template <class T> void Matrix<T>::RMultiply(const Vector<T> &in, Vector<T> &out
216224
for (int i = this->minrow; i <= this->maxrow; i++) {
217225
T k = in[i];
218226

219-
T *src = this->data[i] + this->mincol;
227+
const T *src = this->data[i] + this->mincol;
220228
auto dst = out.begin();
221229
int j = this->maxcol - this->mincol + 1;
222230
while (j--) {
@@ -242,8 +250,10 @@ template <class T> Matrix<T> Matrix<T>::operator*(const T &s) const
242250
{
243251
const Matrix<T> tmp(this->minrow, this->maxrow, this->mincol, this->maxcol);
244252
for (int i = this->minrow; i <= this->maxrow; i++) {
245-
T *src = this->data[i] + this->mincol;
253+
const T *src = this->data[i] + this->mincol;
254+
// NOLINTBEGIN(misc-const-correctness)
246255
T *dst = tmp.data[i] + this->mincol;
256+
// NOLINTEND(misc-const-correctness)
247257
int j = this->maxcol - this->mincol + 1;
248258
while (j--) {
249259
*(dst++) = *(src++) * s;
@@ -256,7 +266,9 @@ template <class T> Matrix<T> Matrix<T>::operator*(const T &s) const
256266
template <class T> Matrix<T> &Matrix<T>::operator*=(const T &s)
257267
{
258268
for (int i = this->minrow; i <= this->maxrow; i++) {
269+
// NOLINTBEGIN(misc-const-correctness)
259270
T *dst = this->data[i] + this->mincol;
271+
// NOLINTEND(misc-const-correctness)
260272
int j = this->maxcol - this->mincol + 1;
261273
while (j--) {
262274
*(dst++) *= s;
@@ -273,8 +285,10 @@ template <class T> Matrix<T> Matrix<T>::operator/(const T &s) const
273285

274286
const Matrix<T> tmp(this->minrow, this->maxrow, this->mincol, this->maxcol);
275287
for (int i = this->minrow; i <= this->maxrow; i++) {
276-
T *src = this->data[i] + this->mincol;
288+
const T *src = this->data[i] + this->mincol;
289+
// NOLINTBEGIN(misc-const-correctness)
277290
T *dst = tmp.data[i] + this->mincol;
291+
// NOLINTEND(misc-const-correctness)
278292
int j = this->maxcol - this->mincol + 1;
279293
while (j--) {
280294
*(dst++) = *(src++) / s;
@@ -290,7 +304,9 @@ template <class T> Matrix<T> &Matrix<T>::operator/=(const T &s)
290304
}
291305

292306
for (int i = this->minrow; i <= this->maxrow; i++) {
307+
// NOLINTBEGIN(misc-const-correctness)
293308
T *dst = this->data[i] + this->mincol;
309+
// NOLINTEND(misc-const-correctness)
294310
int j = this->maxcol - this->mincol + 1;
295311
while (j--) {
296312
*(dst++) /= s;
@@ -328,8 +344,8 @@ template <class T> bool Matrix<T>::operator==(const Matrix<T> &M) const
328344

329345
for (int i = this->minrow; i <= this->maxrow; i++) {
330346
// inner loop
331-
T *src1 = M.data[i] + this->mincol;
332-
T *src2 = this->data[i] + this->mincol;
347+
const T *src1 = M.data[i] + this->mincol;
348+
const T *src2 = this->data[i] + this->mincol;
333349
int j = this->maxcol - this->mincol + 1;
334350
while (j--) {
335351
if (*(src1++) != *(src2++)) {
@@ -346,7 +362,7 @@ template <class T> bool Matrix<T>::operator!=(const Matrix<T> &M) const { return
346362
template <class T> bool Matrix<T>::operator==(const T &s) const
347363
{
348364
for (int i = this->minrow; i <= this->maxrow; i++) {
349-
T *src = this->data[i] + this->mincol;
365+
const T *src = this->data[i] + this->mincol;
350366
int j = this->maxcol - this->mincol + 1;
351367
while (j--) {
352368
if (*(src++) != s) {
@@ -417,8 +433,10 @@ template <class T> void Matrix<T>::Pivot(int row, int col)
417433
mult = this->data[i][col];
418434

419435
// inner loop
420-
T *src = this->data[row] + this->mincol;
436+
const T *src = this->data[row] + this->mincol;
437+
// NOLINTBEGIN(misc-const-correctness)
421438
T *dst = this->data[i] + this->mincol;
439+
// NOLINTEND(misc-const-correctness)
422440
int j = this->maxcol - this->mincol + 1;
423441
while (j--) {
424442
*(dst++) -= *(src++) * mult;

src/core/recarray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ template <class T> template <class Vector> void RectArray<T>::GetRow(int row, Ve
240240
if (!CheckRow(v)) {
241241
throw DimensionException();
242242
}
243-
T *rowptr = data[row];
243+
const T *rowptr = data[row];
244244
for (int i = mincol; i <= maxcol; i++) {
245245
v[i] = rowptr[i];
246246
}

src/core/tinyxml.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ TiXmlBase::StringToBuffer::~StringToBuffer() { delete[] buffer; }
122122

123123
TiXmlNode::~TiXmlNode()
124124
{
125-
TiXmlNode *node = firstChild;
126-
TiXmlNode *temp = nullptr;
125+
const TiXmlNode *node = firstChild;
126+
const TiXmlNode *temp = nullptr;
127127

128128
while (node) {
129129
temp = node;
@@ -140,8 +140,8 @@ void TiXmlNode::CopyTo(TiXmlNode *target) const
140140

141141
void TiXmlNode::Clear()
142142
{
143-
TiXmlNode *node = firstChild;
144-
TiXmlNode *temp = nullptr;
143+
const TiXmlNode *node = firstChild;
144+
const TiXmlNode *temp = nullptr;
145145

146146
while (node) {
147147
temp = node;

src/core/tinyxmlparser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ const char *TiXmlDocument::Parse(const char *p, TiXmlParsingData *prevData, TiXm
716716

717717
// Did we get encoding info?
718718
if (encoding == TIXML_ENCODING_UNKNOWN && node->ToDeclaration()) {
719-
TiXmlDeclaration *dec = node->ToDeclaration();
719+
const TiXmlDeclaration *dec = node->ToDeclaration();
720720
const char *enc = dec->Encoding();
721721
assert(enc);
722722

src/games/behavmixed.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ MixedBehaviorProfile<T>::MixedBehaviorProfile(const MixedStrategyProfile<T> &p_p
137137
GameNodeRep *root = m_support.GetGame()->GetRoot().get();
138138

139139
const StrategySupportProfile &support = p_profile.GetSupport();
140-
GameRep *game = m_support.GetGame().get();
140+
const GameRep *game = m_support.GetGame().get();
141141

142142
for (const auto &player : game->GetPlayers()) {
143143
std::map<GameNode, T> map_nvals, map_bvals;

src/games/gametree.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ GameInfoset GameTreeRep::LeaveInfoset(GameNode p_node)
594594
GameInfoset GameTreeRep::AppendMove(GameNode p_node, GamePlayer p_player, int p_actions,
595595
bool p_generateLabels)
596596
{
597-
GameNodeRep *node = p_node.get();
597+
const GameNodeRep *node = p_node.get();
598598
if (p_actions <= 0 || !node->m_children.empty()) {
599599
throw UndefinedException();
600600
}
@@ -1075,7 +1075,9 @@ void GameTreeRep::BuildUnreachableNodes() const
10751075
std::stack<GameNodeRep *> nodes_to_visit;
10761076
nodes_to_visit.push(subtree_root.get());
10771077
while (!nodes_to_visit.empty()) {
1078+
// NOLINTBEGIN(misc-const-correctness)
10781079
GameNodeRep *current_unreachable_node = nodes_to_visit.top();
1080+
// NOLINTEND(misc-const-correctness)
10791081
nodes_to_visit.pop();
10801082
m_unreachableNodes->insert(current_unreachable_node);
10811083
for (const auto &unreachable_child : current_unreachable_node->GetChildren()) {

0 commit comments

Comments
 (0)