Unknown macro: Detect and warn about unknown macro before throw/return

This commit is contained in:
Daniel Marjamäki 2019-07-16 20:32:46 +02:00
parent 7b48fb6b32
commit b3688f22e8
2 changed files with 12 additions and 0 deletions

View File

@ -9127,6 +9127,12 @@ void Tokenizer::findGarbageCode() const
unknownMacroError(tok->linkAt(1)->previous()); unknownMacroError(tok->linkAt(1)->previous());
} }
// UNKNOWN_MACRO(return)
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "%name% throw|return") && std::isupper(tok->str()[0]))
unknownMacroError(tok);
}
// Assign/increment/decrement literal // Assign/increment/decrement literal
for (const Token *tok = tokens(); tok; tok = tok->next()) { for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "!!) %num%|%str%|%char% %assign%|++|--")) if (Token::Match(tok, "!!) %num%|%str%|%char% %assign%|++|--"))

View File

@ -469,6 +469,8 @@ private:
TEST_CASE(checkConfiguration); TEST_CASE(checkConfiguration);
TEST_CASE(unknownType); // #8952 TEST_CASE(unknownType); // #8952
TEST_CASE(unknownMacroBeforeReturn);
} }
std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) { std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
@ -7914,6 +7916,10 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void unknownMacroBeforeReturn() {
ASSERT_THROW(tokenizeAndStringify("int f() { X return 0; }"), InternalError);
}
}; };
REGISTER_TEST(TestTokenizer) REGISTER_TEST(TestTokenizer)