This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49152] New: Unhelpful diagnostic for iterator dereference
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 24 May 2011 21:30:41 +0000
- Subject: [Bug c++/49152] New: Unhelpful diagnostic for iterator dereference
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49152
Summary: Unhelpful diagnostic for iterator dereference
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
This code, based on what happens in std::find():
#include <vector>
struct X { };
struct Y { } val;
std::vector<X>::iterator first;
bool b = *first == val;
produces this output:
fail.cc:8:20: error: no match for 'operator==' in
'first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with
_Iterator = X*, _Container = std::vector<X>,
__gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = X&]() == val'
or with -fno-pretty-templates
fail.cc:8:20: error: no match for 'operator==' in
'first.__gnu_cxx::__normal_iterator<X*, std::vector<X, std::allocator<X> >
>::operator*() == val'
I have a few problems with the diagnostic, the main ones are
1) Why is the "()" after the "[with ...]" template argument list in the
-fpretty-templates version?
2) "first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*" is an
abomination, "*first" would be far more helpful
3) after all that verbosity about *first, there's no clue what type val is.
To be helpful it should either show something resembling the original source:
*first == val;
or it should show the types involved:
no match for operator== with operands X& and Y&
or it should show both, like clang does:
error: invalid operands to binary expression ('X' and 'struct Y')
bool b = *first == val;
~~~~~~ ^ ~~~
but what we actually have doesn't manage to resemble the original source or
show the types involved