Skip to content

Commit eb5b4d9

Browse files
autoantwortclaude
andcommitted
Keep decltype exception for standards where it is no keyword
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 663d816 commit eb5b4d9

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎lib/tokenize.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9180,7 +9180,7 @@ void Tokenizer::findGarbageCode() const
91809180
// NAME(...):: => NAME is most likely an unknown macro
91819181
// other cases are valid, e.g. (void)::f(), return (T)::x, new (p) ::T, decltype(x)::type
91829182
const Token* const prev = tok->linkAt(-1)->tokAt(-1);
9183-
if (Token::Match(prev, "%name% (") && !prev->isKeyword()) {
9183+
if (Token::Match(prev, "%name% (") && !prev->isKeyword() && prev->str() != "decltype") { // decltype is no keyword before C++11
91849184
if (prev->isUpperCaseName())
91859185
unknownMacroError(prev);
91869186
else

‎test/testtokenize.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8135,7 +8135,7 @@ class TestTokenizer : public TestFixture {
81358135
" *p = -*p;\n"
81368136
"}\n"));
81378137

8138-
ASSERT_NO_THROW(tokenizeAndStringify("void f(void* h) {\n" // cast before global scope operator
8138+
ASSERT_NO_THROW(tokenizeAndStringify("void f(void* h) {\n" // #15079
81398139
" (void)::CloseHandle(h);\n"
81408140
" int i = (int)::GetTickCount();\n"
81418141
" g((unsigned char)::toupper(i));\n"
@@ -8150,6 +8150,12 @@ class TestTokenizer : public TestFixture {
81508150
ASSERT_NO_THROW(tokenizeAndStringify("struct S { using type = int; };\n"
81518151
"S s;\n"
81528152
"decltype(s)::type i;\n"));
8153+
{
8154+
const Settings s = settingsBuilder().cpp(Standards::CPP03).build();
8155+
ASSERT_NO_THROW(tokenizeAndStringify("struct S { typedef int type; };\n"
8156+
"S s;\n"
8157+
"decltype(s)::type i;\n", s));
8158+
}
81538159

81548160
ignore_errout();
81558161

0 commit comments

Comments
 (0)