Skip to content
Merged
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
6 changes: 4 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9177,9 +9177,11 @@ void Tokenizer::findGarbageCode() const
if (!Token::Match(tok->next(), "%name%|*|~") || (tok->next()->isKeyword() && !Token::Match(tok->next(), "new|delete|operator")))
syntaxError(tok);
if (Token::simpleMatch(tok->tokAt(-1), ")")) {
// NAME(...):: => NAME is most likely an unknown macro
// other cases are valid, e.g. (void)::f(), return (T)::x, new (p) ::T, decltype(x)::type
const Token* const prev = tok->linkAt(-1)->tokAt(-1);
if (!Token::Match(prev, "%name% (") || (!prev->isControlFlowKeyword() && prev->str() != "decltype")) {
if (prev && prev->isUpperCaseName())
if (Token::Match(prev, "%name% (") && !prev->isKeyword() && prev->str() != "decltype") { // decltype is no keyword before C++11
if (prev->isUpperCaseName())
unknownMacroError(prev);
else
syntaxError(tok);
Expand Down
22 changes: 22 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8135,6 +8135,28 @@ class TestTokenizer : public TestFixture {
" *p = -*p;\n"
"}\n"));

ASSERT_NO_THROW(tokenizeAndStringify("void f(void* h) {\n" // #15079
" (void)::CloseHandle(h);\n"
" int i = (int)::GetTickCount();\n"
" g((unsigned char)::toupper(i));\n"
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("int f(int i) {\n"
" return (int)::abs(i);\n"
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("namespace N { struct T {}; }\n"
"void f(void* p) {\n"
" new (p) ::N::T;\n"
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("struct S { using type = int; };\n"
"S s;\n"
"decltype(s)::type i;\n"));
{
const Settings s = settingsBuilder().cpp(Standards::CPP03).build();
ASSERT_NO_THROW(tokenizeAndStringify("struct S { typedef int type; };\n"
"S s;\n"
"decltype(s)::type i;\n", s));
}

ignore_errout();

ASSERT_EQUALS(";", tokenizeAndStringify("typedef std::size_t size_t;\n")); // #14809
Expand Down
Loading