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: unassig...@gcc.gnu.org
        ReportedBy: r...@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

Reply via email to