diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index f3d0d5dee..c1f7bb925 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2807,7 +2807,9 @@ bool Type::isClassType() const bool Type::isEnumType() const { - return classScope && classScope->type == Scope::ScopeType::eEnum; + //We explicitly check for "enum" because a forward declared enum doesn't get its own scope + return (classDef && classDef->str() == "enum") || + (classScope && classScope->type == Scope::ScopeType::eEnum); } bool Type::isStructType() const diff --git a/test/testother.cpp b/test/testother.cpp index 032ef3bde..153c01e37 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1614,6 +1614,24 @@ private: " virtual void func(const std::string str) {}\n" "};"); ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'str' should be passed by const reference.\n", errout.str()); + + check("enum X;\n" + "void foo(X x1){}\n"); + ASSERT_EQUALS("", errout.str()); + + check("enum X { a, b, c };\n" + "void foo(X x2){}\n"); + ASSERT_EQUALS("", errout.str()); + + check("enum X { a, b, c };\n" + "enum X;" + "void foo(X x3){}\n"); + ASSERT_EQUALS("", errout.str()); + + check("enum X;\n" + "enum X { a, b, c };" + "void foo(X x4){}\n"); + ASSERT_EQUALS("", errout.str()); } void passedByValue_nonConst() {