Fixed #9812 (False positive; syntax error 'using array_p = const array_t *;')

This commit is contained in:
Daniel Marjamäki 2020-09-14 21:59:41 +02:00
parent 53a0760fdf
commit 3459f0da32
2 changed files with 9 additions and 1 deletions

View File

@ -1554,7 +1554,7 @@ void Tokenizer::simplifyTypedef()
// handle missing variable name // handle missing variable name
if (Token::Match(tok3, "( *|&|&& *|&|&& %name%")) if (Token::Match(tok3, "( *|&|&& *|&|&& %name%"))
tok2 = tok3->tokAt(3); tok2 = tok3->tokAt(3);
else if (Token::Match(tok2->tokAt(3), "[(),]")) else if (Token::Match(tok2->tokAt(3), "[(),;]"))
tok2 = tok2->tokAt(2); tok2 = tok2->tokAt(2);
else else
tok2 = tok2->tokAt(3); tok2 = tok2->tokAt(3);

View File

@ -168,6 +168,7 @@ private:
TEST_CASE(simplifyTypedef130); // ticket #9446 TEST_CASE(simplifyTypedef130); // ticket #9446
TEST_CASE(simplifyTypedef131); // ticket #9446 TEST_CASE(simplifyTypedef131); // ticket #9446
TEST_CASE(simplifyTypedef132); // ticket #9739 - using TEST_CASE(simplifyTypedef132); // ticket #9739 - using
TEST_CASE(simplifyTypedef133); // ticket #9812 - using
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -2653,6 +2654,13 @@ private:
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code, false));
} }
void simplifyTypedef133() { // #9812
const char code[] = "typedef unsigned char array_t[16];\n"
"using array_p = const array_t *;\n"
"array_p x;\n";
ASSERT_EQUALS("using array_p = const unsigned char ( * ) [ 16 ] ; array_p x ;", tok(code, false));
}
void simplifyTypedefFunction1() { void simplifyTypedefFunction1() {
{ {
const char code[] = "typedef void (*my_func)();\n" const char code[] = "typedef void (*my_func)();\n"