Skip to content

Commit 5df6d5b

Browse files
committed
Tokenizer; Warn about unknown macro used in string concatenation
1 parent bf781f7 commit 5df6d5b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9332,6 +9332,15 @@ void Tokenizer::reportUnknownMacros()
93329332
}
93339333
}
93349334
}
9335+
9336+
// String concatenation with unknown macros
9337+
for (const Token *tok = tokens(); tok; tok = tok->next()) {
9338+
if (Token::Match(tok, "%str% %name% (") && Token::Match(tok->linkAt(2), ") %str%")) {
9339+
if (list.isKeyword(tok->next()->str()))
9340+
continue;
9341+
unknownMacroError(tok->next());
9342+
}
9343+
}
93359344
}
93369345

93379346
void Tokenizer::findGarbageCode() const

test/testtokenize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7982,6 +7982,9 @@ class TestTokenizer : public TestFixture {
79827982

79837983
const char code2[] = "void foo() { dostuff(x 0); }";
79847984
ASSERT_THROW(tokenizeAndStringify(code2), InternalError);
7985+
7986+
const char code3[] = "f(\"1\" __stringify(48) \"1\");";
7987+
ASSERT_THROW(tokenizeAndStringify(code3), InternalError);
79857988
}
79867989

79877990
void findGarbageCode() { // Test Tokenizer::findGarbageCode()

0 commit comments

Comments
 (0)