Skip to content

Commit d3e4284

Browse files
Refs #12655: add unknownMacro warning (#6361)
1 parent 05d5710 commit d3e4284

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

lib/tokenize.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8674,8 +8674,6 @@ void Tokenizer::findGarbageCode() const
86748674
if (Token::Match(tok->next(), ")|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&"))
86758675
syntaxError(tok);
86768676
}
8677-
if ((!isCPP() || !Token::simpleMatch(tok->previous(), "operator")) && Token::Match(tok, "[,;] ,"))
8678-
syntaxError(tok);
86798677
if (Token::simpleMatch(tok, ".") &&
86808678
!Token::simpleMatch(tok->previous(), ".") &&
86818679
!Token::simpleMatch(tok->next(), ".") &&
@@ -8703,22 +8701,28 @@ void Tokenizer::findGarbageCode() const
87038701
syntaxError(tok);
87048702
if (Token::Match(tok, "! %comp%"))
87058703
syntaxError(tok);
8706-
if (Token::Match(tok, "] %name%") && (!isCPP() || !(tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "delete ["))))
8707-
syntaxError(tok);
8704+
if (Token::Match(tok, "] %name%") && (!isCPP() || !(tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "delete [")))) {
8705+
if (tok->next()->isUpperCaseName())
8706+
unknownMacroError(tok->next());
8707+
else
8708+
syntaxError(tok);
8709+
}
87088710

87098711
if (tok->link() && Token::Match(tok, "[([]") && (!tok->tokAt(-1) || !tok->tokAt(-1)->isControlFlowKeyword())) {
87108712
const Token* const end = tok->link();
87118713
for (const Token* inner = tok->next(); inner != end; inner = inner->next()) {
87128714
if (inner->str() == "{")
87138715
inner = inner->link();
8714-
else if (inner->str() == ";") {
8716+
else if (inner->str() == ";" || (Token::simpleMatch(inner, ", ,") && (!isCPP() || !Token::simpleMatch(inner->previous(), "operator")))) {
87158717
if (tok->tokAt(-1) && tok->tokAt(-1)->isUpperCaseName())
87168718
unknownMacroError(tok->tokAt(-1));
87178719
else
87188720
syntaxError(inner);
87198721
}
87208722
}
87218723
}
8724+
if ((!isCPP() || !Token::simpleMatch(tok->previous(), "operator")) && Token::Match(tok, "[,;] ,"))
8725+
syntaxError(tok);
87228726
}
87238727

87248728
// ternary operator without :

test/testgarbage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ class TestGarbage : public TestFixture {
12141214
" typedef S0 b[][1][1] != 0\n"
12151215
"};\n"
12161216
"b[K][0] S0 b[][1][1] != 4{ 0 };\n"
1217-
"b[0][0]"), SYNTAX);
1217+
"b[0][0]"), UNKNOWN_MACRO);
12181218
}
12191219

12201220
void garbageCode149() { // #7085

test/testtokenize.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7133,6 +7133,14 @@ class TestTokenizer : public TestFixture {
71337133
InternalError,
71347134
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
71357135

7136+
ASSERT_THROW_EQUALS(tokenizeAndStringify("struct S { int a[2] PACKED; };\n"),
7137+
InternalError,
7138+
"There is an unknown macro here somewhere. Configuration is required. If PACKED is a macro then please configure it.");
7139+
7140+
ASSERT_THROW_EQUALS(tokenizeAndStringify("MACRO(a, b,,)\n"),
7141+
InternalError,
7142+
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
7143+
71367144
ASSERT_THROW_INTERNAL(tokenizeAndStringify("{ for (()()) }"), SYNTAX); // #11643
71377145

71387146
ASSERT_NO_THROW(tokenizeAndStringify("S* g = ::new(ptr) S();")); // #12552

0 commit comments

Comments
 (0)