Fix #10145 FP AssignmentAddressToInteger with enum class (#3810)

This commit is contained in:
chrchr-github 2022-02-08 16:12:35 +01:00 committed by GitHub
parent e64ea20089
commit 2c7948102a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -78,7 +78,7 @@ static bool isEnumStart(const Token* tok)
{
if (!tok || tok->str() != "{")
return false;
return (tok->strAt(-1) == "enum") || (tok->strAt(-2) == "enum");
return (tok->strAt(-1) == "enum") || (tok->strAt(-2) == "enum") || Token::Match(tok->tokAt(-3), "enum class %name%");
}
template<typename T>

View File

@ -161,6 +161,16 @@ private:
" int i = foo->p;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str());
check("struct S {\n" // #10145
" enum class E { e1, e2 };\n"
" E e;\n"
" char* e1;\n"
"};\n"
"void f(S& s) {\n"
" s.e = S::E::e1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void ptrcompare() {