Tokenizer: simplification of typedefs in _Generic arguments (#5059)

This commit is contained in:
Daniel Marjamäki 2023-05-14 15:14:52 +02:00 committed by GitHub
parent 793d6aef01
commit d475591665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -935,6 +935,18 @@ namespace {
return true;
if (Token::Match(tok->previous(), "public|protected|private"))
return true;
if (Token::Match(tok->previous(), ", %name% :")) {
bool isGeneric = false;
for (; tok; tok = tok->previous()) {
if (Token::Match(tok, ")|]"))
tok = tok->link();
else if (Token::Match(tok, "[;{}(]")) {
isGeneric = Token::simpleMatch(tok->previous(), "_Generic (");
break;
}
}
return isGeneric;
}
return false;
}
if (Token::Match(tok->previous(), "%name%") && !tok->previous()->isKeyword())

View File

@ -69,6 +69,7 @@ private:
TEST_CASE(carray2);
TEST_CASE(cdonotreplace1);
TEST_CASE(cppfp1);
TEST_CASE(Generic1);
TEST_CASE(simplifyTypedef1);
TEST_CASE(simplifyTypedef2);
@ -463,6 +464,12 @@ private:
ASSERT_EQUALS("void foo ( void ( * p ) ( void ) ) ;", tok(code));
}
void Generic1() {
const char code[] = "typedef void func(void);\n"
"_Generic((x), func: 1, default: 2);";
ASSERT_EQUALS("_Generic ( x , void ( ) : 1 , default : 2 ) ;", tok(code));
}
void simplifyTypedef1() {
const char code[] = "class A\n"
"{\n"