Skip to content

Commit ab16603

Browse files
authored
fix #9685 (Handle 'extern "C++"') (#2933)
1 parent 14a15fd commit ab16603

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9851,7 +9851,7 @@ void Tokenizer::findGarbageCode() const
98519851
for (const Token *tok = tokens(); tok; tok = tok->next()) {
98529852
if (!Token::simpleMatch(tok, "template <"))
98539853
continue;
9854-
if (tok->previous() && !Token::Match(tok->previous(), "[:;{})>]")) {
9854+
if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|)|>|\"C++\"")) {
98559855
if (tok->previous()->isUpperCaseName())
98569856
unknownMacroError(tok->previous());
98579857
else

test/testsimplifytemplate.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ class TestSimplifyTemplate : public TestFixture {
205205
TEST_CASE(template160);
206206
TEST_CASE(template161);
207207
TEST_CASE(template162);
208+
TEST_CASE(template163); // #9685 syntax error
208209
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
209210
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
210211
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@@ -4108,6 +4109,11 @@ class TestSimplifyTemplate : public TestFixture {
41084109
ASSERT_EQUALS(exp, tok(code));
41094110
}
41104111

4112+
void template163() { // #9685 syntax error
4113+
const char code[] = "extern \"C++\" template < typename T > T * test ( ) { return nullptr ; }";
4114+
ASSERT_EQUALS(code, tok(code));
4115+
}
4116+
41114117
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
41124118
const char code[] = "template <typename T> struct C {};\n"
41134119
"template <typename T> struct S {a};\n"

0 commit comments

Comments
 (0)