Fix #11001 syntaxError for valid C code sizeof(enum ...) (#4045)

This commit is contained in:
chrchr-github 2022-04-26 07:22:53 +02:00 committed by GitHub
parent 961ecfbe33
commit 6b5df68677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -4648,7 +4648,7 @@ const Token * Scope::addEnum(const Token * tok, bool isCpp)
if (tok2 == end) {
tok2 = tok2->next();
if (tok2 && tok2->str() != ";")
if (tok2 && tok2->str() != ";" && (isCpp || tok2->str() != ")"))
tok2 = nullptr;
} else
tok2 = nullptr;

View File

@ -376,6 +376,7 @@ private:
TEST_CASE(enum7);
TEST_CASE(enum8);
TEST_CASE(enum9);
TEST_CASE(enum10); // #11001
TEST_CASE(sizeOfType);
@ -5307,6 +5308,19 @@ private:
ASSERT_EQUALS(X1->value, 8);
}
void enum10() { // #11001
GET_SYMBOL_DB_C("int b = sizeof(enum etag {X, Y});\n");
ASSERT(db != nullptr);
const Enumerator *X = db->scopeList.back().findEnumerator("X");
ASSERT(X);
ASSERT(X->value_known);
ASSERT_EQUALS(X->value, 0);
const Enumerator *Y = db->scopeList.back().findEnumerator("Y");
ASSERT(Y);
ASSERT(Y->value_known);
ASSERT_EQUALS(Y->value, 1);
}
void sizeOfType() {
// #7615 - crash in Symboldatabase::sizeOfType()
GET_SYMBOL_DB("enum e;\n"