Unknown macro: Detect and warn about unknown macro before throw/return
This commit is contained in:
parent
7b48fb6b32
commit
b3688f22e8
|
@ -9127,6 +9127,12 @@ void Tokenizer::findGarbageCode() const
|
|||
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
|
||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "!!) %num%|%str%|%char% %assign%|++|--"))
|
||||
|
|
|
@ -469,6 +469,8 @@ private:
|
|||
TEST_CASE(checkConfiguration);
|
||||
|
||||
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) {
|
||||
|
@ -7914,6 +7916,10 @@ private:
|
|||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void unknownMacroBeforeReturn() {
|
||||
ASSERT_THROW(tokenizeAndStringify("int f() { X return 0; }"), InternalError);
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue