diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2fef6c1f2..96e225f82 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -983,6 +983,23 @@ void Tokenizer::simplifyTemplates() } const std::string type2(s); + if (type.size() != types2.size()) + { + std::list locationList; + ErrorLogger::ErrorMessage::FileLocation loc; + loc.line = tok2->linenr(); + loc.file = file(tok2); + locationList.push_back(loc); + + const ErrorLogger::ErrorMessage errmsg(locationList, + "error", + "Internal error: failed to instantiate template. The checking continues anyway.", + "internalError"); + + _errorLogger->reportErr(errmsg); + break; + } + // New classname/funcname.. const std::string name2(name + "<" + type2 + ">"); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c4cd724d2..c36caf0d1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -91,6 +91,7 @@ private: TEST_CASE(template15); TEST_CASE(template16); TEST_CASE(template_default_parameter); + TEST_CASE(template_default_type); TEST_CASE(template_typename); TEST_CASE(namespaces); @@ -1391,6 +1392,41 @@ private: } } + void template_default_type() + { + const char code[] = "template \n" + "class A\n" + "{\n" + "public:\n" + " void foo() {\n" + " int a;\n" + " a = static_cast(a);\n" + " }\n" + "};\n" + "\n" + "template \n" + "class B\n" + "{\n" + "protected:\n" + " A a;\n" + "};\n" + "\n" + "class C\n" + " : public B\n" + "{\n" + "};\n"; + + errout.str(""); + Settings settings; + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "file1.cpp"); + tokenizer.simplifyTokenList(); + + ASSERT_EQUALS("[file1.cpp:15]: (error) Internal error: failed to instantiate template. The checking continues anyway.\n", errout.str()); + TODO_ASSERT_EQUALS("", errout.str()); + } + void template_typename() { const char code[] = "template \n"