diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 263168a33..8814f636a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8445,9 +8445,12 @@ void Tokenizer::simplifyAttribute() if (!tok->next()->link()->next()) syntaxError(tok); - if (tok->next()->link()->next()->str() == "void") // __attribute__((destructor)) void func() {} + if (tok->next()->link()->next()->str() == "void") { + // __attribute__((destructor)) void func() {} + if (!tok->next()->link()->next()->next()) + syntaxError(tok); tok->next()->link()->next()->next()->isAttributeDestructor(true); - else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // void func() __attribute__((destructor)); + } else if (tok->next()->link()->next()->str() == ";" && tok->linkAt(-1) && tok->previous()->link()->previous()) // void func() __attribute__((destructor)); tok->previous()->link()->previous()->isAttributeDestructor(true); else // void __attribute__((destructor)) func() {} tok->next()->link()->next()->isAttributeDestructor(true); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 0141b3637..c4b2852e7 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -217,6 +217,7 @@ private: TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode183); // #7505 TEST_CASE(garbageCode184); // #7699 + TEST_CASE(garbageCode185); // #7816 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1431,6 +1432,10 @@ private: "}"); } + void garbageCode185() { // #7816 + checkCode("__attribute__((destructor)) void"); + } + void syntaxErrorFirstToken() { ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858