Too Few Template Parameter Lists

TooFewTemplateParameterLists is an error message produced by newer versions of the GnuCpp compiler for code which previously compiled. The problem concerns the initialization of static members of a templated class. Previously it was sufficient to declare the member, but this now has to be preceded by template <>. The difficulty is that the error message says what the problem is in such a way as not to provide a clue as to what to do next. See Example code 1. CppTemplatesTheCompleteGuide gives a different example using a template class with a typed template parameter. See Example code 2. The examples have been run with GnuCpp 4.0.2. -- JohnFletcher
Clang (CeeLanguageFamilyFrontEnd) gives better diagnostics for this.
Example code 1

 template <class T>
 class A
    static int a;
    static const char * const name;

// int A<int>::a = 0; This now fails with "error: too few template-parameter-lists" // This conforms to the CeePlusPlus standard, which older versions of the compiler do not enforce. template<> int A<int>::a = 0; template<> const char * const A<int>::name = "example";

int main() { return 0; }

The Clang diagnostic is like this:

 too_few_1.cpp:12:5: error: template specialization requires 'template<>'
 int A<int>::a = 0; 
 1 error generated.
This tells the user what the problem is, what the solution is and where to put it, except that it seems to be indicating the solution is this, which is also in error:

 int template<> A<int>::a = 0; 
The original is colour coded.

The caret in the diagnostic does not show where the text should be inserted. The text itself is printed out at that position. That's more obvious if there's other stuff on the same line:

 too_few_1.cpp:12:5: error: template specialization requires 'template<>'
 int n; int A<int>::a = 0; 

Example code 2

 #include <iostream>
 template <int I>
 class B
   static int b;

template<> int B<1>::b = 1; template <int I> int B<I>::b = 0;

int main() { std::cout << B<1>::b << std::endl; // 1 std::cout << B<2>::b << std::endl; // 0 return 0; }

CategoryCpp CategoryCppTemplates

View edit of April 2, 2014 or FindPage with title or text search