diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b46e7dd3e..93615f682 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7165,7 +7165,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const if (end) { if (Token::simpleMatch(end, ") {")) { // function parameter ? // 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; // look backwards diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c5592ac5d..50682d84c 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3244,6 +3244,17 @@ private: "void f() { if (aa) ; else if (bb==x) df; }\n"; checkSimplifyEnum(code3); 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