fix daca crash in TemplateSimplifier::getNewName (#2772)

Don't add the same template instantiation multiple times.

Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
IOBYTE 2020-09-04 01:08:28 -04:00 committed by GitHub
parent 84dd0c961f
commit 2db0d2878b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 218 additions and 1 deletions

View File

@ -769,7 +769,15 @@ void TemplateSimplifier::addInstantiation(Token *token, const std::string &scope
{ {
simplifyTemplateArgs(token->tokAt(2), token->next()->findClosingBracket()); simplifyTemplateArgs(token->tokAt(2), token->next()->findClosingBracket());
mTemplateInstantiations.emplace_back(token, scope); TokenAndName instantiation(token, scope);
// check if instantiation already exists before adding it
std::list<TokenAndName>::iterator it = std::find(mTemplateInstantiations.begin(),
mTemplateInstantiations.end(),
instantiation);
if (it == mTemplateInstantiations.end())
mTemplateInstantiations.emplace_back(instantiation);
} }
void TemplateSimplifier::getTemplateInstantiations() void TemplateSimplifier::getTemplateInstantiations()

View File

@ -197,6 +197,7 @@ private:
TEST_CASE(template155); // #9539 TEST_CASE(template155); // #9539
TEST_CASE(template156); TEST_CASE(template156);
TEST_CASE(template157); // #9854 TEST_CASE(template157); // #9854
TEST_CASE(template158); // daca 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)
@ -3767,6 +3768,214 @@ private:
ASSERT_EQUALS(exp, tok(code)); ASSERT_EQUALS(exp, tok(code));
} }
void template158() { // daca crash
const char code[] = "template <typename> class a0{};\n"
"template <typename> class a1{};\n"
"template <typename> class a2{};\n"
"template <typename> class a3{};\n"
"template <typename> class a4{};\n"
"template <typename> class a5{};\n"
"template <typename> class a6{};\n"
"template <typename> class a7{};\n"
"template <typename> class a8{};\n"
"template <typename> class a9{};\n"
"template <typename> class a10{};\n"
"template <typename> class a11{};\n"
"template <typename> class a12{};\n"
"template <typename> class a13{};\n"
"template <typename> class a14{};\n"
"template <typename> class a15{};\n"
"template <typename> class a16{};\n"
"template <typename> class a17{};\n"
"template <typename> class a18{};\n"
"template <typename> class a19{};\n"
"template <typename> class a20{};\n"
"template <typename> class a21{};\n"
"template <typename> class a22{};\n"
"template <typename> class a23{};\n"
"template <typename> class a24{};\n"
"template <typename> class a25{};\n"
"template <typename> class a26{};\n"
"template <typename> class a27{};\n"
"template <typename> class a28{};\n"
"template <typename> class a29{};\n"
"template <typename> class a30{};\n"
"template <typename> class a31{};\n"
"template <typename> class a32{};\n"
"template <typename> class a33{};\n"
"template <typename> class a34{};\n"
"template <typename> class a35{};\n"
"template <typename> class a36{};\n"
"template <typename> class a37{};\n"
"template <typename> class a38{};\n"
"template <typename> class a39{};\n"
"template <typename> class a40{};\n"
"template <typename> class a41{};\n"
"template <typename> class a42{};\n"
"template <typename> class a43{};\n"
"template <typename> class a44{};\n"
"template <typename> class a45{};\n"
"template <typename> class a46{};\n"
"template <typename> class a47{};\n"
"template <typename> class a48{};\n"
"template <typename> class a49{};\n"
"template <typename> class a50{};\n"
"template <typename> class a51{};\n"
"template <typename> class a52{};\n"
"template <typename> class a53{};\n"
"template <typename> class a54{};\n"
"template <typename> class a55{};\n"
"template <typename> class a56{};\n"
"template <typename> class a57{};\n"
"template <typename> class a58{};\n"
"template <typename> class a59{};\n"
"template <typename> class a60{};\n"
"template <typename> class a61{};\n"
"template <typename> class a62{};\n"
"template <typename> class a63{};\n"
"template <typename> class a64{};\n"
"template <typename> class a65{};\n"
"template <typename> class a66{};\n"
"template <typename> class a67{};\n"
"template <typename> class a68{};\n"
"template <typename> class a69{};\n"
"template <typename> class a70{};\n"
"template <typename> class a71{};\n"
"template <typename> class a72{};\n"
"template <typename> class a73{};\n"
"template <typename> class a74{};\n"
"template <typename> class a75{};\n"
"template <typename> class a76{};\n"
"template <typename> class a77{};\n"
"template <typename> class a78{};\n"
"template <typename> class a79{};\n"
"template <typename> class a80{};\n"
"template <typename> class a81{};\n"
"template <typename> class a82{};\n"
"template <typename> class a83{};\n"
"template <typename> class a84{};\n"
"template <typename> class a85{};\n"
"template <typename> class a86{};\n"
"template <typename> class a87{};\n"
"template <typename> class a88{};\n"
"template <typename> class a89{};\n"
"template <typename> class a90{};\n"
"template <typename> class a91{};\n"
"template <typename> class a92{};\n"
"template <typename> class a93{};\n"
"template <typename> class a94{};\n"
"template <typename> class a95{};\n"
"template <typename> class a96{};\n"
"template <typename> class a97{};\n"
"template <typename> class a98{};\n"
"template <typename> class a99{};\n"
"template <typename> class a100{};\n"
"template <typename> class b {};\n"
"b<a0<int>> d0;\n"
"b<a1<int>> d1;\n"
"b<a2<int>> d2;\n"
"b<a3<int>> d3;\n"
"b<a4<int>> d4;\n"
"b<a5<int>> d5;\n"
"b<a6<int>> d6;\n"
"b<a7<int>> d7;\n"
"b<a8<int>> d8;\n"
"b<a9<int>> d9;\n"
"b<a10<int>> d10;\n"
"b<a11<int>> d11;\n"
"b<a12<int>> d12;\n"
"b<a13<int>> d13;\n"
"b<a14<int>> d14;\n"
"b<a15<int>> d15;\n"
"b<a16<int>> d16;\n"
"b<a17<int>> d17;\n"
"b<a18<int>> d18;\n"
"b<a19<int>> d19;\n"
"b<a20<int>> d20;\n"
"b<a21<int>> d21;\n"
"b<a22<int>> d22;\n"
"b<a23<int>> d23;\n"
"b<a24<int>> d24;\n"
"b<a25<int>> d25;\n"
"b<a26<int>> d26;\n"
"b<a27<int>> d27;\n"
"b<a28<int>> d28;\n"
"b<a29<int>> d29;\n"
"b<a30<int>> d30;\n"
"b<a31<int>> d31;\n"
"b<a32<int>> d32;\n"
"b<a33<int>> d33;\n"
"b<a34<int>> d34;\n"
"b<a35<int>> d35;\n"
"b<a36<int>> d36;\n"
"b<a37<int>> d37;\n"
"b<a38<int>> d38;\n"
"b<a39<int>> d39;\n"
"b<a40<int>> d40;\n"
"b<a41<int>> d41;\n"
"b<a42<int>> d42;\n"
"b<a43<int>> d43;\n"
"b<a44<int>> d44;\n"
"b<a45<int>> d45;\n"
"b<a46<int>> d46;\n"
"b<a47<int>> d47;\n"
"b<a48<int>> d48;\n"
"b<a49<int>> d49;\n"
"b<a50<int>> d50;\n"
"b<a51<int>> d51;\n"
"b<a52<int>> d52;\n"
"b<a53<int>> d53;\n"
"b<a54<int>> d54;\n"
"b<a55<int>> d55;\n"
"b<a56<int>> d56;\n"
"b<a57<int>> d57;\n"
"b<a58<int>> d58;\n"
"b<a59<int>> d59;\n"
"b<a60<int>> d60;\n"
"b<a61<int>> d61;\n"
"b<a62<int>> d62;\n"
"b<a63<int>> d63;\n"
"b<a64<int>> d64;\n"
"b<a65<int>> d65;\n"
"b<a66<int>> d66;\n"
"b<a67<int>> d67;\n"
"b<a68<int>> d68;\n"
"b<a69<int>> d69;\n"
"b<a70<int>> d70;\n"
"b<a71<int>> d71;\n"
"b<a72<int>> d72;\n"
"b<a73<int>> d73;\n"
"b<a74<int>> d74;\n"
"b<a75<int>> d75;\n"
"b<a76<int>> d76;\n"
"b<a77<int>> d77;\n"
"b<a78<int>> d78;\n"
"b<a79<int>> d79;\n"
"b<a80<int>> d80;\n"
"b<a81<int>> d81;\n"
"b<a82<int>> d82;\n"
"b<a83<int>> d83;\n"
"b<a84<int>> d84;\n"
"b<a85<int>> d85;\n"
"b<a86<int>> d86;\n"
"b<a87<int>> d87;\n"
"b<a88<int>> d88;\n"
"b<a89<int>> d89;\n"
"b<a90<int>> d90;\n"
"b<a91<int>> d91;\n"
"b<a92<int>> d92;\n"
"b<a93<int>> d93;\n"
"b<a94<int>> d94;\n"
"b<a95<int>> d95;\n"
"b<a96<int>> d96;\n"
"b<a97<int>> d97;\n"
"b<a98<int>> d98;\n"
"b<a99<int>> d99;\n"
"b<a100<int>> d100;";
// don't bother checking the output because this is not instantiated properly
tok(code); // don't crash
}
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"