Handle simple typedefs (#4558)
This commit is contained in:
parent
0fc142c18f
commit
ae16aab997
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 *);";
|
||||||
|
|
Loading…
Reference in New Issue