Fix #10886 FP: Label 'enum' is not used. [unusedLabel] (#3912)

This commit is contained in:
chrchr-github 2022-03-17 17:38:23 +01:00 committed by GitHub
parent 97ce569859
commit 297b0b5c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -2967,7 +2967,7 @@ void CheckOther::checkUnusedLabel()
if (!tok->scope()->isExecutable())
tok = tok->scope()->bodyEnd;
if (Token::Match(tok, "{|}|; %name% :") && tok->strAt(1) != "default") {
if (Token::Match(tok, "{|}|; %name% :") && !tok->tokAt(1)->isKeyword()) {
const std::string tmp("goto " + tok->strAt(1));
if (!Token::findsimplematch(scope->bodyStart->next(), tmp.c_str(), tmp.size(), scope->bodyEnd->previous()))
unusedLabelError(tok->next(), tok->next()->scope()->type == Scope::eSwitch, hasIfdef);

View File

@ -4071,6 +4071,11 @@ private:
" return 1;\n" // <- clarify for tools that function does not continue..
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" enum : uint8_t { A, B } var = A;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}