fix passedByValueError on enums (#2869)

This commit is contained in:
shaneasd 2020-10-31 01:32:35 +08:00 committed by GitHub
parent b96f23a388
commit a623168942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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() {