Fixed #6919: Support initializer list in duplicateEnumError check
This commit is contained in:
parent
d7853b9963
commit
56698dd844
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue