parent
ec15772381
commit
903df84ddc
|
@ -1892,7 +1892,7 @@ static bool isBracketAccess(const Token* tok)
|
|||
}
|
||||
|
||||
static bool isConstant(const Token* tok) {
|
||||
return Token::Match(tok, "%bool%|%num%|%str%|%char%|nullptr|NULL");
|
||||
return tok && (tok->isEnumerator() || Token::Match(tok, "%bool%|%num%|%str%|%char%|nullptr|NULL"));
|
||||
}
|
||||
|
||||
static bool isConstStatement(const Token *tok, bool cpp)
|
||||
|
@ -2072,6 +2072,8 @@ void CheckOther::constStatementError(const Token *tok, const std::string &type,
|
|||
typeStr = "character";
|
||||
else if (isNullOperand(valueTok))
|
||||
typeStr = "NULL";
|
||||
else if (valueTok->isEnumerator())
|
||||
typeStr = "enumerator";
|
||||
msg = "Redundant code: Found a statement that begins with " + typeStr + " constant.";
|
||||
}
|
||||
else if (!tok)
|
||||
|
|
|
@ -703,6 +703,13 @@ private:
|
|||
" auto g = [](decltype(a[0]) i) {};\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("enum E { E0 };\n"
|
||||
"void f() {\n"
|
||||
" E0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with enumerator constant.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void vardecl() {
|
||||
|
|
Loading…
Reference in New Issue