Skip to content

Commit 1d85c3e

Browse files
committed
Check all headers with clang-tidy
1 parent 1f35735 commit 1d85c3e

50 files changed

Lines changed: 271 additions & 344 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Checks: |
1212
cppcoreguidelines-prefer-member-initializer,
1313
misc-const-correctness
1414
WarningsAsErrors: '*'
15-
# Don't bother with wxWidgets headers
1615
HeaderFilterRegex: '.*'
1716
FormatStyle: none
1817
User: arbiter

Makefile.am

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ msw-msi:
636636
light -ext WixUIExtension gambit.wixobj
637637

638638
clang-tidy:
639-
clang-tidy ${top_srcdir}/src/core/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION="" ${WX_CXXFLAGS}
640-
clang-tidy ${top_srcdir}/src/games/*.cc ${top_srcdir}/src/games/*/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION="" ${WX_CXXFLAGS}
641-
clang-tidy ${top_srcdir}/src/solvers/*/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION="" ${WX_CXXFLAGS}
642-
clang-tidy ${top_srcdir}/src/tools/*/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION="" ${WX_CXXFLAGS}
639+
clang-tidy ${top_srcdir}/src/core/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION=""
640+
clang-tidy ${top_srcdir}/src/games/*.cc ${top_srcdir}/src/games/*/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION=""
641+
clang-tidy ${top_srcdir}/src/solvers/*/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION=""
642+
clang-tidy ${top_srcdir}/src/tools/*/*.cc -- --std=c++17 -I ${top_srcdir}/src -DVERSION=""

src/core/tinyxml.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ TiXmlBase::StringToBuffer::StringToBuffer(const TIXML_STRING &str)
120120
TiXmlBase::StringToBuffer::~StringToBuffer() { delete[] buffer; }
121121
// End strange bug fix. -->
122122

123-
TiXmlNode::TiXmlNode(NodeType _type)
124-
: TiXmlBase(), parent(nullptr), type(_type), firstChild(nullptr), lastChild(nullptr),
125-
prev(nullptr), next(nullptr)
126-
{
127-
}
128-
129123
TiXmlNode::~TiXmlNode()
130124
{
131125
TiXmlNode *node = firstChild;

src/core/tinyxml.h

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class TiXmlBase {
267267
{
268268
assert(p);
269269
if (encoding == TIXML_ENCODING_UTF8) {
270-
*length = utf8ByteTable[*((unsigned char *)p)];
270+
*length = utf8ByteTable[*(reinterpret_cast<const unsigned char *>(p))];
271271
assert(*length >= 0 && *length < 5);
272272
}
273273
else {
@@ -652,63 +652,27 @@ class TiXmlNode : public TiXmlBase {
652652
/// Returns true if this node has no children.
653653
bool NoChildren() const { return !firstChild; }
654654

655-
const TiXmlDocument *ToDocument() const
656-
{
657-
return (type == DOCUMENT) ? (const TiXmlDocument *)this : nullptr;
658-
} ///< Cast to a more defined type. Will return null not of the requested type.
659-
const TiXmlElement *ToElement() const
660-
{
661-
return (type == ELEMENT) ? (const TiXmlElement *)this : nullptr;
662-
} ///< Cast to a more defined type. Will return null not of the requested type.
663-
const TiXmlComment *ToComment() const
664-
{
665-
return (type == COMMENT) ? (const TiXmlComment *)this : nullptr;
666-
} ///< Cast to a more defined type. Will return null not of the requested type.
667-
const TiXmlUnknown *ToUnknown() const
668-
{
669-
return (type == UNKNOWN) ? (const TiXmlUnknown *)this : nullptr;
670-
} ///< Cast to a more defined type. Will return null not of the requested type.
671-
const TiXmlText *ToText() const
672-
{
673-
return (type == TEXT) ? (const TiXmlText *)this : nullptr;
674-
} ///< Cast to a more defined type. Will return null not of the requested type.
675-
const TiXmlDeclaration *ToDeclaration() const
676-
{
677-
return (type == DECLARATION) ? (const TiXmlDeclaration *)this : nullptr;
678-
} ///< Cast to a more defined type. Will return null not of the requested type.
655+
const TiXmlDocument *ToDocument() const;
656+
const TiXmlElement *ToElement() const;
657+
const TiXmlComment *ToComment() const;
658+
const TiXmlUnknown *ToUnknown() const;
659+
const TiXmlText *ToText() const;
660+
const TiXmlDeclaration *ToDeclaration() const;
679661

680-
TiXmlDocument *ToDocument()
681-
{
682-
return (type == DOCUMENT) ? (TiXmlDocument *)this : nullptr;
683-
} ///< Cast to a more defined type. Will return null not of the requested type.
684-
TiXmlElement *ToElement()
685-
{
686-
return (type == ELEMENT) ? (TiXmlElement *)this : nullptr;
687-
} ///< Cast to a more defined type. Will return null not of the requested type.
688-
TiXmlComment *ToComment()
689-
{
690-
return (type == COMMENT) ? (TiXmlComment *)this : nullptr;
691-
} ///< Cast to a more defined type. Will return null not of the requested type.
692-
TiXmlUnknown *ToUnknown()
693-
{
694-
return (type == UNKNOWN) ? (TiXmlUnknown *)this : nullptr;
695-
} ///< Cast to a more defined type. Will return null not of the requested type.
696-
TiXmlText *ToText()
697-
{
698-
return (type == TEXT) ? (TiXmlText *)this : nullptr;
699-
} ///< Cast to a more defined type. Will return null not of the requested type.
700-
TiXmlDeclaration *ToDeclaration()
701-
{
702-
return (type == DECLARATION) ? (TiXmlDeclaration *)this : nullptr;
703-
} ///< Cast to a more defined type. Will return null not of the requested type.
662+
TiXmlDocument *ToDocument();
663+
TiXmlElement *ToElement();
664+
TiXmlComment *ToComment();
665+
TiXmlUnknown *ToUnknown();
666+
TiXmlText *ToText();
667+
TiXmlDeclaration *ToDeclaration();
704668

705669
/** Create an exact duplicate of this node and return it. The memory must be deleted
706670
by the caller.
707671
*/
708672
virtual TiXmlNode *Clone() const = 0;
709673

710674
protected:
711-
TiXmlNode(NodeType _type);
675+
TiXmlNode(NodeType _type) : TiXmlBase(), type(_type) {}
712676

713677
// Copy to the allocated object. Shared functionality between Clone, Copy constructor,
714678
// and the assignment operator.
@@ -722,16 +686,16 @@ class TiXmlNode : public TiXmlBase {
722686
// Figure out what is at *p, and parse it. Returns null if it is not an xml node.
723687
TiXmlNode *Identify(const char *start, TiXmlEncoding encoding);
724688

725-
TiXmlNode *parent;
689+
TiXmlNode *parent{nullptr};
726690
NodeType type;
727691

728-
TiXmlNode *firstChild;
729-
TiXmlNode *lastChild;
692+
TiXmlNode *firstChild{nullptr};
693+
TiXmlNode *lastChild{nullptr};
730694

731695
TIXML_STRING value;
732696

733-
TiXmlNode *prev;
734-
TiXmlNode *next;
697+
TiXmlNode *prev{nullptr};
698+
TiXmlNode *next{nullptr};
735699

736700
private:
737701
TiXmlNode(const TiXmlNode &); // not implemented.
@@ -750,29 +714,21 @@ class TiXmlAttribute : public TiXmlBase {
750714

751715
public:
752716
/// Construct an empty attribute.
753-
TiXmlAttribute() : TiXmlBase()
754-
{
755-
document = nullptr;
756-
prev = next = nullptr;
757-
}
717+
TiXmlAttribute() : TiXmlBase(), document(nullptr) { prev = next = nullptr; }
758718

759719
#ifdef TIXML_USE_STL
760720
/// std::string constructor.
761721
TiXmlAttribute(const std::string &_name, const std::string &_value)
722+
: document(nullptr), name(_name), value(_value)
762723
{
763-
name = _name;
764-
value = _value;
765-
document = nullptr;
766724
prev = next = nullptr;
767725
}
768726
#endif
769727

770728
/// Construct an attribute with a name and value.
771729
TiXmlAttribute(const char *_name, const char *_value)
730+
: document(nullptr), name(_name), value(_value)
772731
{
773-
name = _name;
774-
value = _value;
775-
document = nullptr;
776732
prev = next = nullptr;
777733
}
778734

@@ -804,13 +760,13 @@ class TiXmlAttribute : public TiXmlBase {
804760
/// STL std::string form.
805761
void SetName(const std::string &_name)
806762
{
807-
StringToBuffer buf(_name);
763+
const StringToBuffer buf(_name);
808764
SetName(buf.buffer ? buf.buffer : "error");
809765
}
810766
/// STL std::string form.
811767
void SetValue(const std::string &_value)
812768
{
813-
StringToBuffer buf(_value);
769+
const StringToBuffer buf(_value);
814770
SetValue(buf.buffer ? buf.buffer : "error");
815771
}
816772
#endif
@@ -884,12 +840,10 @@ class TiXmlAttributeSet {
884840
const TiXmlAttribute *Find(const char *name) const;
885841
TiXmlAttribute *Find(const char *name);
886842

887-
private:
888-
//*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
889-
//*ME: this class must be also use a hidden/disabled copy-constructor !!!
890843
TiXmlAttributeSet(const TiXmlAttributeSet &) = delete; // not allowed
891844
void operator=(const TiXmlAttributeSet &) = delete; // not allowed (as TiXmlAttribute)
892845

846+
private:
893847
TiXmlAttribute sentinel;
894848
};
895849

@@ -948,7 +902,7 @@ class TiXmlElement : public TiXmlNode {
948902
int QueryFloatAttribute(const char *name, float *_value) const
949903
{
950904
double d;
951-
int result = QueryDoubleAttribute(name, &d);
905+
const int result = QueryDoubleAttribute(name, &d);
952906
if (result == TIXML_SUCCESS) {
953907
*_value = (float)d;
954908
}
@@ -982,16 +936,16 @@ class TiXmlElement : public TiXmlNode {
982936
/// STL std::string form.
983937
void SetAttribute(const std::string &name, const std::string &_value)
984938
{
985-
StringToBuffer n(name);
986-
StringToBuffer v(_value);
939+
const StringToBuffer n(name);
940+
const StringToBuffer v(_value);
987941
if (n.buffer && v.buffer) {
988942
SetAttribute(n.buffer, v.buffer);
989943
}
990944
}
991945
///< STL std::string form.
992946
void SetAttribute(const std::string &name, int _value)
993947
{
994-
StringToBuffer n(name);
948+
const StringToBuffer n(name);
995949
if (n.buffer) {
996950
SetAttribute(n.buffer, _value);
997951
}
@@ -1139,23 +1093,24 @@ class TiXmlText : public TiXmlNode {
11391093
normal, encoded text. If you want it be output as a CDATA text
11401094
element, set the parameter _cdata to 'true'
11411095
*/
1142-
TiXmlText(const char *initValue) : TiXmlNode(TiXmlNode::TEXT)
1096+
TiXmlText(const char *initValue) : TiXmlNode(TiXmlNode::TEXT), cdata(false)
11431097
{
11441098
SetValue(initValue);
1145-
cdata = false;
11461099
}
11471100
~TiXmlText() override = default;
11481101

11491102
#ifdef TIXML_USE_STL
11501103
/// Constructor.
1151-
TiXmlText(const std::string &initValue) : TiXmlNode(TiXmlNode::TEXT)
1104+
TiXmlText(const std::string &initValue) : TiXmlNode(TiXmlNode::TEXT), cdata(false)
11521105
{
11531106
SetValue(initValue);
1154-
cdata = false;
11551107
}
11561108
#endif
11571109

1158-
TiXmlText(const TiXmlText &copy) : TiXmlNode(TiXmlNode::TEXT) { copy.CopyTo(this); }
1110+
TiXmlText(const TiXmlText &copy) : TiXmlNode(TiXmlNode::TEXT), cdata(copy.cdata)
1111+
{
1112+
copy.CopyTo(this);
1113+
}
11591114
void operator=(const TiXmlText &base) { base.CopyTo(this); }
11601115

11611116
/// Write this text object to a FILE stream.
@@ -1314,12 +1269,12 @@ class TiXmlDocument : public TiXmlNode {
13141269
bool LoadFile(const std::string &filename,
13151270
TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING) ///< STL std::string version.
13161271
{
1317-
StringToBuffer f(filename);
1272+
const StringToBuffer f(filename);
13181273
return (f.buffer && LoadFile(f.buffer, encoding));
13191274
}
13201275
bool SaveFile(const std::string &filename) const ///< STL std::string version.
13211276
{
1322-
StringToBuffer f(filename);
1277+
const StringToBuffer f(filename);
13231278
return (f.buffer && SaveFile(f.buffer));
13241279
}
13251280
#endif
@@ -1517,9 +1472,9 @@ class TiXmlDocument : public TiXmlNode {
15171472
class TiXmlHandle {
15181473
public:
15191474
/// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
1520-
TiXmlHandle(TiXmlNode *_node) { this->node = _node; }
1475+
TiXmlHandle(TiXmlNode *_node) : node(_node) {}
15211476
/// Copy constructor
1522-
TiXmlHandle(const TiXmlHandle &ref) { this->node = ref.node; }
1477+
TiXmlHandle(const TiXmlHandle &ref) = default;
15231478
TiXmlHandle operator=(const TiXmlHandle &ref)
15241479
{
15251480
this->node = ref.node;
@@ -1590,6 +1545,56 @@ class TiXmlHandle {
15901545
TiXmlNode *node;
15911546
};
15921547

1548+
inline const TiXmlDocument *TiXmlNode::ToDocument() const
1549+
{
1550+
return (type == DOCUMENT) ? dynamic_cast<const TiXmlDocument *>(this) : nullptr;
1551+
}
1552+
inline const TiXmlElement *TiXmlNode::ToElement() const
1553+
{
1554+
return (type == ELEMENT) ? dynamic_cast<const TiXmlElement *>(this) : nullptr;
1555+
}
1556+
inline const TiXmlComment *TiXmlNode::ToComment() const
1557+
{
1558+
return (type == COMMENT) ? dynamic_cast<const TiXmlComment *>(this) : nullptr;
1559+
}
1560+
inline const TiXmlUnknown *TiXmlNode::ToUnknown() const
1561+
{
1562+
return (type == UNKNOWN) ? dynamic_cast<const TiXmlUnknown *>(this) : nullptr;
1563+
}
1564+
inline const TiXmlText *TiXmlNode::ToText() const
1565+
{
1566+
return (type == TEXT) ? dynamic_cast<const TiXmlText *>(this) : nullptr;
1567+
}
1568+
inline const TiXmlDeclaration *TiXmlNode::ToDeclaration() const
1569+
{
1570+
return (type == DECLARATION) ? dynamic_cast<const TiXmlDeclaration *>(this) : nullptr;
1571+
}
1572+
1573+
inline TiXmlDocument *TiXmlNode::ToDocument()
1574+
{
1575+
return (type == DOCUMENT) ? dynamic_cast<TiXmlDocument *>(this) : nullptr;
1576+
}
1577+
inline TiXmlElement *TiXmlNode::ToElement()
1578+
{
1579+
return (type == ELEMENT) ? dynamic_cast<TiXmlElement *>(this) : nullptr;
1580+
}
1581+
inline TiXmlComment *TiXmlNode::ToComment()
1582+
{
1583+
return (type == COMMENT) ? dynamic_cast<TiXmlComment *>(this) : nullptr;
1584+
}
1585+
inline TiXmlUnknown *TiXmlNode::ToUnknown()
1586+
{
1587+
return (type == UNKNOWN) ? dynamic_cast<TiXmlUnknown *>(this) : nullptr;
1588+
}
1589+
inline TiXmlText *TiXmlNode::ToText()
1590+
{
1591+
return (type == TEXT) ? dynamic_cast<TiXmlText *>(this) : nullptr;
1592+
}
1593+
inline TiXmlDeclaration *TiXmlNode::ToDeclaration()
1594+
{
1595+
return (type == DECLARATION) ? dynamic_cast<TiXmlDeclaration *>(this) : nullptr;
1596+
}
1597+
15931598
#ifdef _MSC_VER
15941599
#pragma warning(pop)
15951600
#endif

src/games/agg/agg.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ AGG::AGG(int numPlayers, std::vector<int> &_actions, int numANodes, int _numPNod
3838
vector<projtype> &projTypes, vector<vector<aggdistrib>> &projS,
3939
vector<vector<vector<config>>> &proj, vector<vector<projtype>> &projF,
4040
vector<vector<vector<int>>> &Po, vector<aggdistrib> &P, vector<aggpayoff> &_payoffs)
41-
: numPlayers(numPlayers), totalActions(0), maxActions(0), numActionNodes(numANodes),
42-
numPNodes(_numPNodes), actionSets(_actionSets), neighbors(neighb), projectionTypes(projTypes),
43-
payoffs(_payoffs), projection(proj), projectedStrat(projS), fullProjectedStrat(projS),
44-
projFunctions(projF), Porder(Po), Pr(P), isPure(numANodes, true),
45-
node2Action(numANodes, vector<int>(numPlayers)), cache(numPlayers + 1),
46-
player2Class(numPlayers), kSymStrategyOffset(1, 0)
41+
: numPlayers(numPlayers), numActionNodes(numANodes), numPNodes(_numPNodes),
42+
actionSets(_actionSets), neighbors(neighb), projectionTypes(projTypes), payoffs(_payoffs),
43+
projection(proj), projectedStrat(projS), fullProjectedStrat(projS), projFunctions(projF),
44+
Porder(Po), Pr(P), isPure(numANodes, true), node2Action(numANodes, vector<int>(numPlayers)),
45+
cache(numPlayers + 1), player2Class(numPlayers), kSymStrategyOffset(1, 0)
4746

4847
{
4948
// actions

src/games/agg/agg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class AGG {
170170
int numPlayers;
171171
std::vector<int> actions;
172172
std::vector<int> strategyOffset;
173-
int totalActions;
174-
int maxActions;
173+
int totalActions{0};
174+
int maxActions{0};
175175

176176
int numActionNodes; // |S|
177177
int numPNodes; // |P|

0 commit comments

Comments
 (0)