Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9166,9 +9166,19 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "==|!=|<=|>= %comp%") && tok->strAt(-1) != "operator")
syntaxError(tok, tok->str() + " " + tok->strAt(1));
if (Token::simpleMatch(tok, "::") && (!Token::Match(tok->next(), "%name%|*|~") ||
(tok->next()->isKeyword() && !Token::Match(tok->next(), "new|delete|operator"))))
syntaxError(tok);
if (Token::simpleMatch(tok, "::")) {
if (!Token::Match(tok->next(), "%name%|*|~") || (tok->next()->isKeyword() && !Token::Match(tok->next(), "new|delete|operator")))
syntaxError(tok);
if (Token::simpleMatch(tok->tokAt(-1), ")")) {
const Token* const prev = tok->linkAt(-1)->tokAt(-1);
if (!Token::Match(prev, "%name% (") || (!prev->isControlFlowKeyword() && prev->str() != "decltype")) {
if (prev && prev->isUpperCaseName())
unknownMacroError(prev);
else
syntaxError(tok);
}
}
}
if (Token::Match(tok, "& %comp%|&&|%oror%|&|%or%") && tok->strAt(1) != ">")
syntaxError(tok);
if (Token::Match(tok, "%comp%|&&|%oror%|&|%or% }") && tok->str() != ">")
Expand Down
5 changes: 2 additions & 3 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3773,9 +3773,8 @@ class TestSymbolDatabase : public TestFixture {
}

void symboldatabase35() { // ticket #4806 and #4841
check("class FragmentQueue : public CL_NS(util)::PriorityQueue<CL_NS(util)::Deletor::Object<TextFragment> >\n"
"{};\n");
ASSERT_EQUALS("", errout_str());
ASSERT_THROW_INTERNAL(check("class FragmentQueue : public CL_NS(util)::PriorityQueue<CL_NS(util)::Deletor::Object<TextFragment> >\n"
"{};\n"), UNKNOWN_MACRO);
}

void symboldatabase36() { // ticket #4892
Expand Down
10 changes: 10 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7910,6 +7910,16 @@ class TestTokenizer : public TestFixture {
" return std::string{ g() + \"abc\" MACRO \"def\" };\n"
"}\n"), UNKNOWN_MACRO);

ASSERT_THROW_INTERNAL(tokenizeAndStringify("namespace N {\n"
" struct C {\n"
" void f();\n"
" };\n"
" void C(abc)::f() {\n"
" X x;\n"
" N::Y([&] { x(); })->g();\n"
" }\n"
"}\n"), UNKNOWN_MACRO);

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("static void handle_toggle(void (*proc) PROTO_XT_CALLBACK_ARGS, int var) {}\n"), // #13198
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If PROTO_XT_CALLBACK_ARGS is a macro then please configure it.");
Expand Down
Loading