Fix #11772 top() on empty stack in TypedefSimplifier::replace() (#5161)

This commit is contained in:
chrchr-github 2023-06-16 19:35:01 +02:00 committed by GitHub
parent aca6c47024
commit 1ffff8dc06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -665,14 +665,14 @@ namespace {
}
for (Token* type = start; Token::Match(type, "%name%|*|&"); type = type->next()) {
if (Token::Match(type, "%name% ;") && !type->isStandardType()) {
if (type != start && Token::Match(type, "%name% ;") && !type->isStandardType()) {
mRangeType.first = start;
mRangeType.second = type;
mNameToken = type;
mEndToken = mNameToken->next();
return;
}
if (Token::Match(type, "%name% [")) {
if (type != start && Token::Match(type, "%name% [")) {
Token* end = type->linkAt(1);
while (Token::simpleMatch(end, "] ["))
end = end->linkAt(1);

View File

@ -3352,6 +3352,19 @@ private:
" a** p = new a * [N];\n"
"}\n";
TODO_ASSERT_EQUALS("does not compile", "void f ( int N ) { int ( * * p ) [ 7 ] ; p = new int ( * ) [ N ] [ 7 ] ; }", tok(code));
// #11772
code = "typedef t;\n" // don't crash on implicit int
"void g() {\n"
" sizeof(t);\n"
"}\n";
ASSERT_EQUALS("void g ( ) { sizeof ( t ) ; }", tok(code)); // TODO: handle implicit int
code = "typedef t[3];\n"
"void g() {\n"
" sizeof(t);\n"
"}\n";
ASSERT_EQUALS("void g ( ) { sizeof ( t ) ; }", tok(code)); // TODO: handle implicit int
}
void simplifyTypedefFunction1() {