From ab16603666396b8e127e316702439285a85c70cc Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Sat, 5 Dec 2020 03:26:11 -0500 Subject: [PATCH] fix #9685 (Handle 'extern "C++"') (#2933) --- lib/tokenize.cpp | 2 +- test/testsimplifytemplate.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d3a3e575a..49b5d7e53 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9851,7 +9851,7 @@ void Tokenizer::findGarbageCode() const for (const Token *tok = tokens(); tok; tok = tok->next()) { if (!Token::simpleMatch(tok, "template <")) continue; - if (tok->previous() && !Token::Match(tok->previous(), "[:;{})>]")) { + if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|)|>|\"C++\"")) { if (tok->previous()->isUpperCaseName()) unknownMacroError(tok->previous()); else diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index d771b4273..0441e69f0 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -205,6 +205,7 @@ private: TEST_CASE(template160); TEST_CASE(template161); TEST_CASE(template162); + TEST_CASE(template163); // #9685 syntax error TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -4108,6 +4109,11 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template163() { // #9685 syntax error + const char code[] = "extern \"C++\" template < typename T > T * test ( ) { return nullptr ; }"; + ASSERT_EQUALS(code, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"