fix daca2 gdcm template simplifier crash (#3221)

This only fixes the crash. The templates that are instantiated are
correct but one template is left uninstantiated. Fixing the missing
instantiation is not easy and will be looked at later.

Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
IOBYTE 2021-04-19 03:17:49 -04:00 committed by GitHub
parent c1bb1d771b
commit 59f7b937f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -2928,7 +2928,7 @@ std::string TemplateSimplifier::getNewName(
} }
if (Token::Match(tok3->tokAt(-2), "<|,|:: %name% <") && (tok3->strAt(1) == ">" || templateParameters(tok3))) if (Token::Match(tok3->tokAt(-2), "<|,|:: %name% <") && (tok3->strAt(1) == ">" || templateParameters(tok3)))
++indentlevel; ++indentlevel;
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]")) else if (indentlevel > 0 && Token::Match(tok3, "> ,|>|::"))
--indentlevel; --indentlevel;
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) { if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]")) {
mTypesUsedInTemplateInstantiation.emplace_back(tok3, ""); mTypesUsedInTemplateInstantiation.emplace_back(tok3, "");

View File

@ -212,6 +212,7 @@ private:
TEST_CASE(template168); TEST_CASE(template168);
TEST_CASE(template169); TEST_CASE(template169);
TEST_CASE(template170); // crash TEST_CASE(template170); // crash
TEST_CASE(template171); // crash
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)
@ -4368,6 +4369,27 @@ private:
ASSERT_EQUALS(exp, tok(code)); ASSERT_EQUALS(exp, tok(code));
} }
void template171() { // crash
const char code[] = "template <int> struct c { enum { b }; };\n"
"template <int> struct h { enum { d }; enum { e }; };\n"
"template <int f, long = h<f>::d, int g = h<f>::e> class i { enum { e = c<g>::b }; };\n"
"void j() { i<2> a; }";
const char exp[] = "struct c<h<2>::e> ; "
"struct h<2> ; "
"class i<2,h<2>::d,h<2>::e> ; "
"void j ( ) { i<2,h<2>::d,h<2>::e> a ; } "
"class i<2,h<2>::d,h<2>::e> { enum Anonymous3 { e = c<h<2>::e> :: b } ; } ; "
"struct h<2> { enum Anonymous1 { d } ; enum Anonymous2 { e } ; } ; "
"struct c<h<2>::e> { enum Anonymous0 { b } ; } ;";
const char act[] = "struct c<h<2>::e> ; "
"template < int > struct h { enum Anonymous1 { d } ; enum Anonymous2 { e } ; } ; "
"class i<2,h<2>::d,h<2>::e> ; "
"void j ( ) { i<2,h<2>::d,h<2>::e> a ; } "
"class i<2,h<2>::d,h<2>::e> { enum Anonymous3 { e = c<h<2>::e> :: b } ; } ; "
"struct c<h<2>::e> { enum Anonymous0 { b } ; } ;";
TODO_ASSERT_EQUALS(exp, act, 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"