Skip to content

Commit 5979eec

Browse files
IOBYTEdanmar
authored andcommitted
Fix 9518 (Syntax error on valid C++) (cppcheck-opensource#2424)
1 parent 7da68bf commit 5979eec

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ namespace {
18111811
return false;
18121812
}
18131813

1814-
if (Token::Match(tok1->tokAt(-1), "class|struct|union|enum")) {
1814+
if (Token::Match(tok1->tokAt(-1), "class|struct|union|enum|namespace")) {
18151815
// fixme
18161816
return false;
18171817
}

test/testsimplifyusing.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TestSimplifyUsing : public TestFixture {
6868
TEST_CASE(simplifyUsing9381);
6969
TEST_CASE(simplifyUsing9385);
7070
TEST_CASE(simplifyUsing9388);
71+
TEST_CASE(simplifyUsing9518);
7172
}
7273

7374
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@@ -619,6 +620,16 @@ class TestSimplifyUsing : public TestFixture {
619620
ASSERT_EQUALS(exp, tok(code, false));
620621
}
621622

623+
void simplifyUsing9518() {
624+
const char code[] = "namespace a {\n"
625+
"using a = enum {};\n"
626+
"}";
627+
const char exp[] = "namespace a { "
628+
"enum a { } ; "
629+
"}";
630+
ASSERT_EQUALS(exp, tok(code, false));
631+
}
632+
622633
};
623634

624635
REGISTER_TEST(TestSimplifyUsing)

0 commit comments

Comments
 (0)