Ticket #8550: Properly simplify "typedef class A B;". (#1224)

This commit is contained in:
Simon Martin 2018-05-12 10:20:33 +02:00 committed by amai2012
parent d4fa8c6e95
commit 16e1e1d8f9
2 changed files with 17 additions and 1 deletions

View File

@ -1254,7 +1254,7 @@ void Tokenizer::simplifyTypedef()
structRemoved = true;
typeStart = typeStart->next();
}
if (typeStart->str() == "struct" && Token::Match(tok2, "%name% ::"))
if (Token::Match(typeStart, "struct|class") && Token::Match(tok2, "%name% ::"))
typeStart = typeStart->next();
if (sameStartEnd)

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(tokenize34); // #8031
TEST_CASE(tokenize35); // #8361
TEST_CASE(tokenize36); // #8436
TEST_CASE(tokenize37); // #8550
TEST_CASE(validate);
@ -857,6 +858,21 @@ private:
ASSERT_EQUALS(code, tokenizeAndStringify(code));
}
void tokenize37() { // #8550
const char codeC[] = "class name { public: static void init ( ) {} } ; "
"typedef class name N; "
"void foo ( ) { return N :: init ( ) ; }";
const char expC [] = "class name { public: static void init ( ) { } } ; "
"void foo ( ) { return name :: init ( ) ; }";
ASSERT_EQUALS(expC, tokenizeAndStringify(codeC));
const char codeS[] = "class name { public: static void init ( ) {} } ; "
"typedef struct name N; "
"void foo ( ) { return N :: init ( ) ; }";
const char expS [] = "class name { public: static void init ( ) { } } ; "
"void foo ( ) { return name :: init ( ) ; }";
ASSERT_EQUALS(expS, tokenizeAndStringify(codeS));
}
void validate() {
// C++ code in C file
ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,false,Settings::Native,"test.c"), InternalError);