Fixed #11232 (Syntax Error: AST broken, binary operator '!=' doesn't have two operands)
This commit is contained in:
parent
f0ac0d8910
commit
5e0fc24bb7
|
@ -1390,10 +1390,19 @@ void Tokenizer::simplifyTypedef()
|
||||||
if (sameStartEnd)
|
if (sameStartEnd)
|
||||||
typeEnd = typeStart;
|
typeEnd = typeStart;
|
||||||
|
|
||||||
|
// Is this a "T()" expression where T is a pointer type?
|
||||||
|
const bool isPointerTypeCall = !inOperator && Token::Match(tok2, "%name% ( )") && !pointers.empty();
|
||||||
|
|
||||||
// start substituting at the typedef name by replacing it with the type
|
// start substituting at the typedef name by replacing it with the type
|
||||||
Token* replStart = tok2; // track first replaced token
|
Token* replStart = tok2; // track first replaced token
|
||||||
for (Token* tok3 = typeStart; tok3->str() != ";"; tok3 = tok3->next())
|
for (Token* tok3 = typeStart; tok3->str() != ";"; tok3 = tok3->next())
|
||||||
tok3->isSimplifiedTypedef(true);
|
tok3->isSimplifiedTypedef(true);
|
||||||
|
if (isPointerTypeCall) {
|
||||||
|
tok2->deleteThis();
|
||||||
|
tok2->insertToken("0");
|
||||||
|
tok2 = tok2->next();
|
||||||
|
tok2->next()->insertToken("0");
|
||||||
|
}
|
||||||
tok2->str(typeStart->str());
|
tok2->str(typeStart->str());
|
||||||
|
|
||||||
// restore qualification if it was removed
|
// restore qualification if it was removed
|
||||||
|
|
|
@ -188,6 +188,7 @@ private:
|
||||||
TEST_CASE(simplifyTypedef139);
|
TEST_CASE(simplifyTypedef139);
|
||||||
TEST_CASE(simplifyTypedef140); // #10798
|
TEST_CASE(simplifyTypedef140); // #10798
|
||||||
TEST_CASE(simplifyTypedef141); // #10144
|
TEST_CASE(simplifyTypedef141); // #10144
|
||||||
|
TEST_CASE(simplifyTypedef142); // T() when T is a pointer type
|
||||||
|
|
||||||
TEST_CASE(simplifyTypedefFunction1);
|
TEST_CASE(simplifyTypedefFunction1);
|
||||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||||
|
@ -3051,6 +3052,18 @@ private:
|
||||||
ASSERT_EQUALS("class C { struct I { } ; } ;", tok(code));
|
ASSERT_EQUALS("class C { struct I { } ; } ;", tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyTypedef142() { // T() when T is a pointer type
|
||||||
|
// #11232
|
||||||
|
const char code1[] = "typedef int* T;\n"
|
||||||
|
"a = T();\n";
|
||||||
|
ASSERT_EQUALS("a = ( int * ) 0 ;", tok(code1));
|
||||||
|
|
||||||
|
// #9479
|
||||||
|
const char code2[] = "typedef int* T;\n"
|
||||||
|
"void f(T = T()){}\n";
|
||||||
|
ASSERT_EQUALS("void f ( int * = ( int * ) 0 ) { }", tok(code2));
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyTypedefFunction1() {
|
void simplifyTypedefFunction1() {
|
||||||
{
|
{
|
||||||
const char code[] = "typedef void (*my_func)();\n"
|
const char code[] = "typedef void (*my_func)();\n"
|
||||||
|
|
Loading…
Reference in New Issue