Fixed #6919: Support initializer list in duplicateEnumError check

This commit is contained in:
Philipp Kloke 2015-08-29 22:20:09 +02:00
parent d7853b9963
commit 56698dd844
2 changed files with 12 additions and 1 deletions

View File

@ -7165,7 +7165,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const
if (end) { if (end) {
if (Token::simpleMatch(end, ") {")) { // function parameter ? if (Token::simpleMatch(end, ") {")) { // function parameter ?
// make sure it's not a conditional // make sure it's not a conditional
if (Token::Match(end->link()->previous(), "if|for|while|switch|BOOST_FOREACH")) if (Token::Match(end->link()->previous(), "if|for|while|switch|BOOST_FOREACH") || Token::Match(end->link()->tokAt(-2), ":|,"))
return false; return false;
// look backwards // look backwards

View File

@ -3244,6 +3244,17 @@ private:
"void f() { if (aa) ; else if (bb==x) df; }\n"; "void f() { if (aa) ; else if (bb==x) df; }\n";
checkSimplifyEnum(code3); checkSimplifyEnum(code3);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// avoid false positive: Initializer list
const char code4[] = "struct S {\n"
" enum { E = 1 };\n"
" explicit S(float f)\n"
" : f_(f * E)\n"
" {}\n"
" float f_;\n"
"};";
checkSimplifyEnum(code4);
ASSERT_EQUALS("", errout.str());
} }
void enum23() { // ticket #2804 void enum23() { // ticket #2804