LWN.net Logo

I have to disagree:

I have to disagree:

Posted Jun 19, 2008 15:09 UTC (Thu) by hummassa (subscriber, #307)
In reply to: C++0x to save the day by pynm0001
Parent article: Converting GCC to C++

> But why are we complaining about this anyways?  unwieldy compiler error
> messages *are* a problem, and if were as simple as simply changing the
> compiler a bit that would have already been done.  Even scripts that
> try to condense the error messages down a bit after the fact don't
> help.  Concepts allow you to fail-fast when compiling.

This is wrong in many levels; I don't know where to start... so, I'll 
reply to your example:

> error: foo.cpp:15 -- Cannot instantiate template<class T> Foo with T =
> Widget because Widget is not Iterable (concept defined in foo.h:17).

The correct error message would be IMHO:

error: foo.cpp:15 -- cannot instantiate template<class T> Foo with T = 
Widget because Widget::operator++(int) nor ::operator++(Widget&,int) 
exists. Foo<T> is defined at foo.h:20 and uses said operator at foo.h:25.

This is feasible because when Foo<T> was defined, it already had the 
information that T needed T::operator*() or ::operator*(T&) and 
T::operator++(int) or ::operator++(T&, int), just because foo.h:25 is:

while( *t++ ) { do_something_with(t); }

I understand that "Widget is not Iterable" is even easier than "Widget:: 
operator*() not defined", so I still think that concepts are a good idea 
as documentation facilities, but I can't agree that good error 
messages "were impossible to attain before concepts".

Just for the kicks, I tried to see what would be the error message in 
such a case:

> um.cc: In static member function 'static int Foo<T>::foo(T) [with T =
> std::basic_string<char, std::char_traits<char>, std::allocator<char>
> >]':
> um.cc:16:   instantiated from here
> um.cc:8: error: no 'operator++(int)' declared for postfix '++', trying
> prefix operator instead
> um.cc:8: error: no match for 'operator++' in '++x'

um.cc:8 is the usage of *t++ in Foo<T>::foo(T); actually, the message 
contains almost every single useful bit of information, but in a garbled 
way: it satys that the problem is the usage of a postfix ++ in line 8, 
when instantiated on line 16. But it forgets to say what type it's 
instantiated to... this can't be hard to correct IMHO.


(Log in to post comments)

I have to disagree:

Posted Jun 19, 2008 18:08 UTC (Thu) by nix (subscriber, #2304) [Link]

The [with T=...] bit says what the type the template is being instantiated 
with is. (Ow. Nasty center-embedding. Sorry.)

Many days later...

Posted Aug 24, 2008 11:08 UTC (Sun) by hummassa (subscriber, #307) [Link]

I forgot to explain that it doesn't say the "most short, meaningful to the
lines where the error ocurred name", /in/ /casu/ "std::string".

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds