diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index da4cc7fbb..4408d7e52 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -69,6 +69,7 @@ private: TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); + TEST_CASE(templateSimplifierCrashes); } std::string checkCode(const char code[], const char filename[] = "test.cpp") { @@ -380,6 +381,77 @@ private: checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991) } + + void templateSimplifierCrashes() { + checkCode( //5950 + "struct A { \n" + " template operator T*();\n" + "}; \n" + "\n" + "template <> A::operator char*(){ return 0; } // specialization\n" + "\n" + "int main() { \n" + " A a;\n" + " int *ip = a.operator int*();\n" + "}\n" + "\n" + "namespace PR5742 {\n" + " template struct A { };\n" + " struct S {\n" + " template operator T();\n" + " } s;\n" + " void f() {\n" + " s.operator A >();\n" + " }\n" + "}\n"); + + checkCode( // 6034 + "template class T, typename... Args>\n" + "struct foo > {\n" + " const bool value = true;\n" + "};\n" + "\n" + "template\n" + "struct int_\n" + "{};\n" + "\n" + "int main() {\n" + " foo >::value;\n" + "}\n" + ); + + checkCode(" > template < . > struct Y < T > { = } ;\n"); //6108 + + checkCode( // 6117 + "template struct something_like_tuple\n" + "{};\n" + "template struct is_last {\n" + " static const bool value = false;\n" + "};\n" + "template class Tuple, typename ... Head>\n" + "struct is_last>\n" + "{\n" + " static const bool value = true;\n" + "};\n" + "\n" + "#define SA(X) static_assert (X, #X)\n" + "\n" + "typedef something_like_tuple something_like_tuple_t;\n" + "SA ((is_last::value == false));\n" + "SA ((is_last::value == false));\n" + ); + + checkCode( //6225 + "template \n" + "void templ_fun_with_ty_pack() {}\n" + " \n" + "namespace PR20047 {\n" + " template \n" + " struct A {};\n" + " using AliasA = A;\n" + "}\n" + ); + } }; REGISTER_TEST(TestGarbage)