fix #9685 (Handle 'extern "C++"') (#2933)

This commit is contained in:
IOBYTE 2020-12-05 03:26:11 -05:00 committed by GitHub
parent 14a15fde65
commit ab16603666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -9851,7 +9851,7 @@ void Tokenizer::findGarbageCode() const
for (const Token *tok = tokens(); tok; tok = tok->next()) { for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (!Token::simpleMatch(tok, "template <")) if (!Token::simpleMatch(tok, "template <"))
continue; continue;
if (tok->previous() && !Token::Match(tok->previous(), "[:;{})>]")) { if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|)|>|\"C++\"")) {
if (tok->previous()->isUpperCaseName()) if (tok->previous()->isUpperCaseName())
unknownMacroError(tok->previous()); unknownMacroError(tok->previous());
else else

View File

@ -205,6 +205,7 @@ private:
TEST_CASE(template160); TEST_CASE(template160);
TEST_CASE(template161); TEST_CASE(template161);
TEST_CASE(template162); TEST_CASE(template162);
TEST_CASE(template163); // #9685 syntax error
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..}; TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
@ -4108,6 +4109,11 @@ private:
ASSERT_EQUALS(exp, tok(code)); 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 <typename T> struct S<C<T>> {..}; void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n" const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n" "template <typename T> struct S {a};\n"