template simplifier: fix explicit instantiation with types starting with const and ending in * and &. (#1530)

This commit is contained in:
IOBYTE 2018-12-19 15:59:59 -05:00 committed by amai2012
parent f8b8597a9b
commit c31331d085
3 changed files with 15 additions and 2 deletions

View File

@ -555,7 +555,7 @@ void TemplateSimplifier::getTemplateInstantiations()
const Token *tok2 = Token::findmatch(tok, "{|;");
if (tok2 && tok2->str() == "{")
tok = tok2->link();
} else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|. %name% ::|<") ||
} else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|.|*|& %name% ::|<") ||
Token::Match(tok->previous(), "%type% %name% ::|<") ||
Token::Match(tok->tokAt(-2), "[,:] private|protected|public %name% ::|<")) {

View File

@ -6073,7 +6073,7 @@ void Tokenizer::simplifyStaticConst()
if (behindOther)
break;
if (!Token::Match(leftTok, "%type%|struct|::") ||
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator"))) {
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator|template"))) {
break;
}
}

View File

@ -124,6 +124,7 @@ private:
TEST_CASE(template84); // #8880
TEST_CASE(template85); // #8902 crash
TEST_CASE(template86); // crash
TEST_CASE(template87);
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_enum); // #6299 Syntax error in complex enum declaration (including template)
@ -1651,6 +1652,18 @@ private:
tok(code);
}
void template87() {
const char code[] = "template<typename T>\n"
"T f1(T t) { return t; }\n"
"template const char * f1<const char *>();\n"
"template const char & f1<const char &>();";
const char exp[] = "const char * f1<constchar*> ( const char * t ) ; "
"const char & f1<constchar&> ( const char & t ) ; "
"const char * f1<constchar*> ( const char * t ) { return t ; } "
"const char & f1<constchar&> ( const char & t ) { return t ; }";
ASSERT_EQUALS(exp, tok(code));
}
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"