Skip to content

Commit 4a53d04

Browse files
authored
fix #13924: FP unknownMacro for C++ keyword in C code (danmar#7578)
1 parent f5007b4 commit 4a53d04

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8574,7 +8574,7 @@ void Tokenizer::findGarbageCode() const
85748574
unknownMacroError(tok->linkAt(1)->previous());
85758575

85768576
// UNKNOWN_MACRO(return)
8577-
else if (!tok->isKeyword() && Token::Match(tok, "%name% throw|return"))
8577+
else if (!tok->isKeyword() && (Token::Match(tok, "%name% return") || (isCPP() && Token::Match(tok, "%name% throw"))))
85788578
unknownMacroError(tok);
85798579

85808580
// Assign/increment/decrement literal

test/testtokenize.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ class TestTokenizer : public TestFixture {
436436

437437
TEST_CASE(unknownMacroBeforeReturn);
438438

439+
TEST_CASE(cppKeywordInCSource);
440+
439441
TEST_CASE(cppcast);
440442

441443
TEST_CASE(checkHeader1);
@@ -7950,6 +7952,10 @@ class TestTokenizer : public TestFixture {
79507952
ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }"), UNKNOWN_MACRO);
79517953
}
79527954

7955+
void cppKeywordInCSource() {
7956+
ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}", true, Platform::Type::Native, false));
7957+
}
7958+
79537959
void cppcast() {
79547960
const char code[] = "a = const_cast<int>(x);\n"
79557961
"a = dynamic_cast<int>(x);\n"

0 commit comments

Comments
 (0)