Fixed #5212 (Tokenizer::simplifyEnum bad simplification of enum value (1<<0)|(1<<1))
This commit is contained in:
parent
f599e3184c
commit
7938692b01
|
@ -7884,11 +7884,13 @@ void Tokenizer::simplifyEnum()
|
|||
}
|
||||
|
||||
if (simplify) {
|
||||
if (ev->value)
|
||||
if (ev->value) {
|
||||
tok2->str(ev->value->str());
|
||||
else {
|
||||
if (hasClass)
|
||||
tok2->deleteNext(2);
|
||||
} else {
|
||||
tok2 = tok2->previous();
|
||||
tok2->deleteNext();
|
||||
tok2->deleteNext(hasClass ? 3 : 1);
|
||||
bool hasOp = false;
|
||||
int indentlevel = 0;
|
||||
for (const Token *enumtok = ev->start; enumtok != ev->end; enumtok = enumtok->next()) {
|
||||
|
@ -7907,13 +7909,10 @@ void Tokenizer::simplifyEnum()
|
|||
tok2 = copyTokens(startPar, ev->start, ev->end);
|
||||
tok2->insertToken(")");
|
||||
Token::createMutualLinks(startPar, tok2->next());
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
}
|
||||
|
||||
if (hasClass) {
|
||||
tok2->deleteNext(2);
|
||||
}
|
||||
|
||||
simplify = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -375,6 +375,7 @@ private:
|
|||
TEST_CASE(enum38); // ticket #4463 (when throwing enum id, don't warn about shadow variable)
|
||||
TEST_CASE(enum39); // ticket #5145 (fp variable hides enum)
|
||||
TEST_CASE(enum40);
|
||||
TEST_CASE(enum41); // ticket #5212 (valgrind errors during enum simplification)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||
|
||||
|
@ -7500,6 +7501,18 @@ private:
|
|||
ASSERT_EQUALS("void f ( ) { x = y + ( 3 ) ; }", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enum41() { // ticket #5212 (valgrind errors during enum simplification)
|
||||
const char code[] = "namespace Foo {\n"
|
||||
" enum BarConfig {\n"
|
||||
" eBitOne = (1 << 0),\n"
|
||||
" eBitTwo = (1 << 1),\n"
|
||||
" eAll = eBitOne|eBitTwo\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"int x = Foo::eAll;";
|
||||
ASSERT_EQUALS("int x ; x = ( 1 ) | 2 ;", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||
"void bar() { int a = A; }";
|
||||
|
|
Loading…
Reference in New Issue