diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index ad4b44942..adf1feeba 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -60,6 +60,10 @@ void CheckClass::constructors() if (!scope->isClassOrStruct()) continue; + // don't check uninstantiated template classes + if (scope->classDef->strAt(-1) == ">") + continue; + // There are no constructors. if (scope->numConstructors == 0) { // If there is a private variable, there should be a constructor.. diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 0fc7e0e37..0a7f853ef 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -58,6 +58,7 @@ private: TEST_CASE(simple3); TEST_CASE(simple4); TEST_CASE(simple5); // ticket #2560 + TEST_CASE(simple6); // ticket #4085 - uninstantiated template class TEST_CASE(initvar_with_this); // BUG 2190300 TEST_CASE(initvar_if); // BUG 2190290 @@ -268,6 +269,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void simple6() { // ticket #4085 - uninstantiated template class + check("template struct A {\n" + " A() { x = 0; }\n" + "private:\n" + " int x;\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void initvar_with_this() { check("struct Fred\n" "{\n"