From 5979eec2c07e58e5ed40139db94b1ad3ca1de102 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Thu, 5 Dec 2019 14:51:36 -0500 Subject: [PATCH] Fix 9518 (Syntax error on valid C++) (#2424) --- lib/tokenize.cpp | 2 +- test/testsimplifyusing.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2d866dd9c..13ee9de8b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1811,7 +1811,7 @@ namespace { return false; } - if (Token::Match(tok1->tokAt(-1), "class|struct|union|enum")) { + if (Token::Match(tok1->tokAt(-1), "class|struct|union|enum|namespace")) { // fixme return false; } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index a959859a9..6c47905c4 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -68,6 +68,7 @@ private: TEST_CASE(simplifyUsing9381); TEST_CASE(simplifyUsing9385); TEST_CASE(simplifyUsing9388); + TEST_CASE(simplifyUsing9518); } std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { @@ -619,6 +620,16 @@ private: ASSERT_EQUALS(exp, tok(code, false)); } + void simplifyUsing9518() { + const char code[] = "namespace a {\n" + "using a = enum {};\n" + "}"; + const char exp[] = "namespace a { " + "enum a { } ; " + "}"; + ASSERT_EQUALS(exp, tok(code, false)); + } + }; REGISTER_TEST(TestSimplifyUsing)