diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 466374866..b20507cdc 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4710,13 +4710,15 @@ const Token * Scope::addEnum(const Token * tok, bool isCpp) const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set& tokensThatAreNotEnumeratorValues) const { - const Scope * scope = tok->scope(); - - const std::string &tokStr = tok->str(); - - if (tokensThatAreNotEnumeratorValues.find(tokStr) != tokensThatAreNotEnumeratorValues.end()) { + if (tok->isKeyword()) return nullptr; - } + + const std::string& tokStr = tok->str(); + + if (tokensThatAreNotEnumeratorValues.find(tokStr) != tokensThatAreNotEnumeratorValues.end()) + return nullptr; + + const Scope* scope = tok->scope(); // check for qualified name if (tok->strAt(-1) == "::") { @@ -4758,22 +4760,22 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set::const_iterator it = scope->nestedList.begin(), end = scope->nestedList.end(); it != end; ++it) { enumerator = (*it)->findEnumerator(tokStr); - if (enumerator) + if (enumerator && !(enumerator->scope && enumerator->scope->enumClass)) return enumerator; } } } } - } else { + } else { // unqualified name const Enumerator * enumerator = scope->findEnumerator(tokStr); - if (enumerator) + if (enumerator && !(enumerator->scope && enumerator->scope->enumClass)) return enumerator; for (std::vector::const_iterator s = scope->nestedList.begin(); s != scope->nestedList.end(); ++s) { enumerator = (*s)->findEnumerator(tokStr); - if (enumerator) + if (enumerator && !(enumerator->scope && enumerator->scope->enumClass)) return enumerator; } @@ -4784,7 +4786,7 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::setclassScope) { enumerator = derivedFromType->classScope->findEnumerator(tokStr); - if (enumerator) + if (enumerator && !(enumerator->scope && enumerator->scope->enumClass)) return enumerator; } } @@ -4798,13 +4800,13 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::setfindEnumerator(tokStr); - if (enumerator) + if (enumerator && !(enumerator->scope && enumerator->scope->enumClass)) return enumerator; for (std::vector::const_iterator s = scope->nestedList.begin(); s != scope->nestedList.end(); ++s) { enumerator = (*s)->findEnumerator(tokStr); - if (enumerator) + if (enumerator && !(enumerator->scope && enumerator->scope->enumClass)) return enumerator; } } diff --git a/test/testbool.cpp b/test/testbool.cpp index 5a23165f1..775bac519 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -1137,6 +1137,23 @@ private: ASSERT_EQUALS("", errout.str()); } + void comparisonOfBoolWithInt10() { // #10935 + check("enum class E { H = 2 };\n" + "template \n" + "void f(bool v) {\n" + " if (v == H) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("namespace N {\n" + " enum class E { H = 2 };\n" + "}\n" + "void f(bool v) {\n" + " if (v == N::H) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void pointerArithBool1() { // #5126 check("void f(char *p) {\n"