Skip to content

Commit dad374c

Browse files
authored
CheckClass: renamed Bool enum values (#8187)
In AIX, TRUE and FALSE are already defined in AIX system header files. As a result, compiling cppcheck in AIX fails with the following errors: ``` /home/buildusr/cppcheck/lib/checkclass.h:231:38: error: expected identifier before numeric constant 231 | enum class Bool : std::uint8_t { TRUE, FALSE, BAILOUT }; | ^~~~ /home/buildusr/cppcheck/lib/checkclass.h:231:38: error: expected '}' before numeric constant In file included from /home/buildusr/cppcheck/lib/astutils.cpp:37: /home/buildusr/cppcheck/lib/checkclass.h:231:36: note: to match this '{' 231 | enum class Bool : std::uint8_t { TRUE, FALSE, BAILOUT }; | ^ In file included from /opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/10/include-fixed/wchar.h:50, from /opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/10/include/c++/cwchar:44, from /opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/10/include/c++/bits/postypes.h:40, from /opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/10/include/c++/bits/char_traits.h:40, from /opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/10/include/c++/string:40, from /home/buildusr/cppcheck/lib/matchcompiler.h:23, from /home/buildusr/cppcheck/build/lib/build/mc_astutils.cpp:1: /home/buildusr/cppcheck/lib/checkclass.h:231:38: error: expected unqualified-id before numeric constant 231 | enum class Bool : std::uint8_t { TRUE, FALSE, BAILOUT }; | ^~~~ In file included from /home/buildusr/cppcheck/lib/astutils.cpp:37: /home/buildusr/cppcheck/lib/checkclass.h:232:12: error: 'Bool' does not name a type; did you mean 'bool'? 232 | static Bool isInverted(const Token *tok, const Token *rhs); | ^~~~ | bool /home/buildusr/cppcheck/lib/checkclass.h:236:60: error: non-member function 'bool isMemberVar(const Scope*, const Token*)' cannot have cv-qualifier 236 | bool isMemberVar(const Scope *scope, const Token *tok) const; | ^~~~~ /home/buildusr/cppcheck/lib/checkclass.h:240:97: error: non-member function 'bool checkConstFunc(const Scope*, const Function*, MemberAccess&)' cannot have cv-qualifier 240 | bool checkConstFunc(const Scope *scope, const Function *func, MemberAccess& memberAccessed) const; | ^~~~~ /home/buildusr/cppcheck/lib/checkclass.h:313:137: error: non-member function 'void initializeVarList(const Function&, std::__cxx11::list<const Function*>&, const Scope*, std::vector<Usage>&)' cannot have cv-qualifier 313 | void initializeVarList(const Function &func, std::list<const Function *> &callstack, const Scope *scope, std::vector<Usage> &usage) const; | ^~~~~ /home/buildusr/cppcheck/lib/checkclass.h:344:1: error: expected declaration before '}' token 344 | }; | ^ ``` In this PR, TRUE and FALSE is being renamed to True and False to resolve this issue. Please let me know your suggestions or concerns on these changes.
1 parent cc24161 commit dad374c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/checkclass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,24 +1872,24 @@ CheckClass::Bool CheckClass::isInverted(const Token *tok, const Token *rhs)
18721872
|| (Token::simpleMatch(itr->astOperand2(), "this") && Token::simpleMatch(itr->astOperand1(), "&") && Token::simpleMatch(itr->astOperand1()->next(), rhs->str().c_str(), rhs->str().size())))) {
18731873
//Do nothing
18741874
} else {
1875-
return Bool::BAILOUT;
1875+
return Bool::Bailout;
18761876
}
18771877
}
18781878
if (res)
1879-
return Bool::TRUE;
1880-
return Bool::FALSE;
1879+
return Bool::True;
1880+
return Bool::False;
18811881
}
18821882

18831883
const Token * CheckClass::getIfStmtBodyStart(const Token *tok, const Token *rhs)
18841884
{
18851885
const Token *top = tok->astTop();
18861886
if (Token::simpleMatch(top->link(), ") {")) {
18871887
switch (isInverted(tok->astParent(), rhs)) {
1888-
case Bool::BAILOUT:
1888+
case Bool::Bailout:
18891889
return nullptr;
1890-
case Bool::TRUE:
1890+
case Bool::True:
18911891
return top->link()->next();
1892-
case Bool::FALSE:
1892+
case Bool::False:
18931893
return top->link()->linkAt(1);
18941894
}
18951895
}

lib/checkclass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class CPPCHECKLIB CheckClass : public Check {
228228
bool hasAllocation(const Function *func, const Scope* scope, const Token *start, const Token *end) const;
229229
bool hasAllocationInIfScope(const Function *func, const Scope* scope, const Token *ifStatementScopeStart) const;
230230
static bool hasAssignSelf(const Function *func, const Token *rhs, const Token *&out_ifStatementScopeStart);
231-
enum class Bool : std::uint8_t { TRUE, FALSE, BAILOUT };
231+
enum class Bool : std::uint8_t { True, False, Bailout };
232232
static Bool isInverted(const Token *tok, const Token *rhs);
233233
static const Token * getIfStmtBodyStart(const Token *tok, const Token *rhs);
234234

0 commit comments

Comments
 (0)