Handle simple typedefs (#4558)

This commit is contained in:
chrchr-github 2022-10-22 00:28:05 +02:00 committed by GitHub
parent 0fc142c18f
commit ae16aab997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -742,14 +742,16 @@ void Tokenizer::simplifyTypedef()
typeStart = tokOffset; typeStart = tokOffset;
while (Token::Match(tokOffset, "const|struct|enum %type%") || while (Token::Match(tokOffset, "const|struct|enum %type%") ||
(tokOffset->next() && tokOffset->next()->isStandardType())) (tokOffset->next() && tokOffset->next()->isStandardType() && !Token::Match(tokOffset->next(), "%name% ;")))
tokOffset = tokOffset->next(); tokOffset = tokOffset->next();
typeEnd = tokOffset; typeEnd = tokOffset;
if (!Token::Match(tokOffset->next(), "%name% ;"))
tokOffset = tokOffset->next(); tokOffset = tokOffset->next();
while (Token::Match(tokOffset, "%type%") && while (Token::Match(tokOffset, "%type%") &&
(tokOffset->isStandardType() || Token::Match(tokOffset, "unsigned|signed"))) { (tokOffset->isStandardType() || Token::Match(tokOffset, "unsigned|signed")) &&
!Token::Match(tokOffset->next(), "%name% ;")) {
typeEnd = tokOffset; typeEnd = tokOffset;
tokOffset = tokOffset->next(); tokOffset = tokOffset->next();
} }

View File

@ -2545,11 +2545,12 @@ private:
void simplifyTypedef124() { // ticket #7792 void simplifyTypedef124() { // ticket #7792
const char code[] = "typedef long unsigned int size_t;\n" const char code[] = "typedef long unsigned int size_t;\n"
"typedef size_t (my_func)(char *, size_t, size_t, void *);"; "typedef size_t (my_func)(char *, size_t, size_t, void *);"
"size_t f(size_t s);";
// Check for output.. const char exp[] = "long f ( long s ) ;";
checkSimplifyTypedef(code); ASSERT_EQUALS(exp, tok(code, /*simplify*/ true));
ASSERT_EQUALS_WITHOUT_LINENUMBERS("[test.cpp:1]: (debug) Failed to parse 'typedef long unsigned int size_t ;'. The checking continues anyway.\n", errout.str()); ASSERT_EQUALS("", errout.str());
const char code1[] = "typedef long unsigned int uint32_t;\n" const char code1[] = "typedef long unsigned int uint32_t;\n"
"typedef uint32_t (my_func)(char *, uint32_t, uint32_t, void *);"; "typedef uint32_t (my_func)(char *, uint32_t, uint32_t, void *);";