0

GCC has a very verbose format for certain template error messages:

... some_class<A,B,C> [with int A = 1, int B = 2, int C = 3]

Any chance to make it show something like:

... some_class<1,2,3>
uj2
  • 2,255
  • 2
  • 21
  • 32

3 Answers3

3

You will lose track from what template the specialization comes from:

template<int A, int B> class X {
  void f();
};

template<int A> class X<A, 2> {
  void f();
};

int main() {
  X<1, 2>().f();
  X<2, 1>().f();
}

GCC outputs

m.cpp: In function 'int main()':
m.cpp:6:12: error: 'void X<A, 2>::f() [with int A = 1]' is private
m.cpp:10:19: error: within this context
m.cpp:2:12: error: 'void X<A, B>::f() [with int A = 2, int B = 1]' is private
m.cpp:11:19: error: within this context

If it just said X<1, 2> and X<2, 1> you would lose an important information that this diagnostic contains.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
  • The former format is more informative no doubt about it, I wasn't implying that it's generally bad. Still, it can quickly become unreadable. Btw, it could have shown something like: `X<1,(2)>` & `X<2,1>` to mark what arguments come from explicit specialization. – uj2 Aug 23 '10 at 11:46
1

No, unless you are willing to maintain a private branch of GCC's source.

Although it is reasonable to want this for class templates, function templates may overload against each other and have different template argument lists for the same function. Then the latter style of error would be ambiguous.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
1

Use the option -fno-pretty-templates. This does what you want, and also omits default template arguments.

Sameer
  • 2,435
  • 23
  • 13
  • It is quite the opposite; from the manual: When an error message refers to a specialization of a class template, the compiler omits any template arguments that match the default template arguments for that template. If either of these behaviors make it harder to understand the error message rather than easier, you can use -fno-pretty-templates to disable them. – hannes Feb 25 '13 at 10:57
  • Please try compiling this simple program with and without the option. main() { vector v; v.pop_back(); }. The option -fno-pretty-templates removes [with T=int], etc. from the error messages. – Sameer May 30 '13 at 22:45