Fixed #6806 (wrong enum simplification in initialization list)
This commit is contained in:
parent
f8bf2b5776
commit
f781f13997
|
@ -7748,14 +7748,13 @@ void Tokenizer::simplifyEnum()
|
||||||
}
|
}
|
||||||
} else if (tok2->str() == "{")
|
} else if (tok2->str() == "{")
|
||||||
++level;
|
++level;
|
||||||
else if (!pattern.empty() && ((tok2->str() == "enum" && Token::simpleMatch(tok2->next(), pattern.c_str())) || Token::simpleMatch(tok2, pattern.c_str()))) {
|
else if (!pattern.empty() && Token::Match(tok2, ("enum| " + pattern).c_str())) {
|
||||||
simplify = true;
|
simplify = true;
|
||||||
hasClass = true;
|
hasClass = true;
|
||||||
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {
|
} else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) {
|
||||||
if (tok2->strAt(-1) == "::") {
|
if (!Token::Match(tok2->previous(), "%op%|::|:") &&
|
||||||
// Don't replace this enum if it's preceded by "::"
|
!Token::simpleMatch(tok2->tokAt(-2), ") ,") &&
|
||||||
} else if (tok2->next() &&
|
Token::Match(tok2->next(), "%name%|(")) {
|
||||||
(tok2->next()->isName() || tok2->next()->str() == "(")) {
|
|
||||||
simplify = true;
|
simplify = true;
|
||||||
hasClass = false;
|
hasClass = false;
|
||||||
} else if (tok2->previous()->str() == "(" && tok2->next()->str() == ")") {
|
} else if (tok2->previous()->str() == "(" && tok2->next()->str() == ")") {
|
||||||
|
|
|
@ -200,6 +200,7 @@ private:
|
||||||
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
|
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
|
||||||
TEST_CASE(enum43); // lhs in assignment
|
TEST_CASE(enum43); // lhs in assignment
|
||||||
TEST_CASE(enum44);
|
TEST_CASE(enum44);
|
||||||
|
TEST_CASE(enum45); // ticket #6806 (enum in init list)
|
||||||
TEST_CASE(enumscope1); // ticket #3949
|
TEST_CASE(enumscope1); // ticket #3949
|
||||||
TEST_CASE(enumOriginalName)
|
TEST_CASE(enumOriginalName)
|
||||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||||
|
@ -3297,6 +3298,12 @@ private:
|
||||||
ASSERT_EQUALS("( datemask_traits < datemask < 'Y' , 'Y' , 'Y' , 'Y' , '/' , 'M' , 'M' , '/' , 'D' , 'D' > > :: value ) ;", checkSimplifyEnum(code2));
|
ASSERT_EQUALS("( datemask_traits < datemask < 'Y' , 'Y' , 'Y' , 'Y' , '/' , 'M' , 'M' , '/' , 'D' , 'D' > > :: value ) ;", checkSimplifyEnum(code2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enum45() { // #6806 - enum in init list
|
||||||
|
const char code[] = "enum a {};\n"
|
||||||
|
"c::c() : a(0), a(0) {}";
|
||||||
|
ASSERT_EQUALS("c :: c ( ) : a ( 0 ) , a ( 0 ) { }", checkSimplifyEnum(code));
|
||||||
|
}
|
||||||
|
|
||||||
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||||
"void bar() { int a = A; }";
|
"void bar() { int a = A; }";
|
||||||
|
|
Loading…
Reference in New Issue