template simplifier: also check if instantiated template is not specialized (#1551)

This commit is contained in:
IOBYTE 2018-12-31 15:29:53 -05:00 committed by Daniel Marjamäki
parent e259e7bc6c
commit c37b807613
2 changed files with 26 additions and 1 deletions

View File

@ -1733,7 +1733,8 @@ bool TemplateSimplifier::matchSpecialization(
} }
// No specialization matches. Return true if the declaration is not a specialization. // No specialization matches. Return true if the declaration is not a specialization.
return Token::Match(templateDeclarationNameToken, "%name% !!<"); return Token::Match(templateDeclarationNameToken, "%name% !!<") &&
(templateDeclarationNameToken->str().find('<') == std::string::npos);
} }
std::string TemplateSimplifier::getNewName( std::string TemplateSimplifier::getNewName(

View File

@ -129,6 +129,7 @@ private:
TEST_CASE(template89); // #8917 TEST_CASE(template89); // #8917
TEST_CASE(template90); // crash TEST_CASE(template90); // crash
TEST_CASE(template91); TEST_CASE(template91);
TEST_CASE(template92);
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)
@ -1809,6 +1810,29 @@ private:
} }
} }
void template92() {
const char code[] = "template<class T> void foo(T const& t) { }\n"
"template<> void foo<double>(double const& d) { }\n"
"template void foo<float>(float const& f);\n"
"int main() {\n"
" foo<int>(2);\n"
" foo<double>(3.14);\n"
" foo<float>(3.14f);\n"
"}";
const char exp[] = "void foo<double> ( const double & d ) ; "
"void foo<float> ( const float & t ) ; "
"void foo<int> ( const int & t ) ; "
"void foo<double> ( const double & d ) { } "
"int main ( ) { "
"foo<int> ( 2 ) ; "
"foo<double> ( 3.14 ) ; "
"foo<float> ( 3.14f ) ; "
"} "
"void foo<float> ( const float & t ) { } "
"void foo<int> ( const int & t ) { }";
ASSERT_EQUALS(exp, 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"