This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/65218] New: [C++11] Complicated diagnostic of erroneous range expression over a pointer type


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65218

            Bug ID: 65218
           Summary: [C++11] Complicated diagnostic of erroneous range
                    expression over a pointer type
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jgreenhalgh at gcc dot gnu.org
              Host: *-*-*
            Target: *-*-*

Created attachment 34881
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34881&action=edit
Testcase to produce the diagnostic

For the attached testcase, the error is that foo has pointer-to-vector type and
so cannot be used in a range expression. However, foo points to a vector, which
can be used in a range expression, and it is likely that this is what the user
intended.

For the attached testcase, my Clang installation (3.5.0-development timescale)
prints:

foo.cpp:9:17: error: invalid range expression of type
'std::vector<std::pair<unsigned int, unsigned int> *> *'; did you mean to
dereference it with '*'?
  for (auto i : foo)
                ^
                *
1 error generated.

By contrast, GCC's diagnostic looks like this:

--------

foo.cpp: In function 'unsigned int bar()':
foo.cpp:9:17: error: no matching function for call to
'begin(std::vector<std::pair<unsigned int, unsigned int>*>*&)'
   for (auto i : foo)
                 ^
In file included from .../include/c++/5.0.0/vector:66:0,
                 from foo.cpp:1:
.../include/c++/5.0.0/bits/range_access.h:87:5: note: candidate: template<class
_Tp, long unsigned int _Nm> _Tp* std::begin(_Tp (&)[_Nm])
     begin(_Tp (&__arr)[_Nm])
     ^
.../include/c++/5.0.0/bits/range_access.h:87:5: note:   template argument
deduction/substitution failed:
foo.cpp:9:17: note:   mismatched types '_Tp [_Nm]' and
'std::vector<std::pair<unsigned int, unsigned int>*>*'
   for (auto i : foo)
                 ^
In file included from .../include/c++/5.0.0/vector:66:0,
                 from foo.cpp:1:
.../include/c++/5.0.0/bits/range_access.h:58:5: note: candidate: template<class
_Container> decltype (__cont.begin()) std::begin(const _Container&)
     begin(const _Container& __cont) -> decltype(__cont.begin())
     ^
.../include/c++/5.0.0/bits/range_access.h:58:5: note:   template argument
deduction/substitution failed:
.../include/c++/5.0.0/bits/range_access.h: In substitution of 'template<class
_Container> decltype (__cont.begin()) std::begin(const _Container&) [with
_Container = std::vector<std::pair<unsigned int, unsigned int>*>*]':
foo.cpp:9:17:   required from here
.../include/c++/5.0.0/bits/range_access.h:58:5: error: request for member
'begin' in '__cont', which is of pointer type 'std::vector<std::pair<unsigned
int, unsigned int>*>* const' (maybe you meant to use '->' ?)
.../include/c++/5.0.0/bits/range_access.h:48:5: note: candidate: template<class
_Container> decltype (__cont.begin()) std::begin(_Container&)
     begin(_Container& __cont) -> decltype(__cont.begin())
     ^
.../include/c++/5.0.0/bits/range_access.h:48:5: note:   template argument
deduction/substitution failed:
.../include/c++/5.0.0/bits/range_access.h: In substitution of 'template<class
_Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container
= std::vector<std::pair<unsigned int, unsigned int>*>*]':
foo.cpp:9:17:   required from here
.../include/c++/5.0.0/bits/range_access.h:48:5: error: request for member
'begin' in '__cont', which is of pointer type 'std::vector<std::pair<unsigned
int, unsigned int>*>*' (maybe you meant to use '->' ?)
In file included from .../include/c++/5.0.0/bits/stl_vector.h:63:0,
                 from .../include/c++/5.0.0/vector:64,
                 from foo.cpp:1:
.../include/c++/5.0.0/initializer_list:89:5: note: candidate: template<class
_Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
     begin(initializer_list<_Tp> __ils) noexcept
     ^
.../include/c++/5.0.0/initializer_list:89:5: note:   template argument
deduction/substitution failed:
foo.cpp:9:17: note:   mismatched types 'std::initializer_list<_Tp>' and
'std::vector<std::pair<unsigned int, unsigned int>*>*'
   for (auto i : foo)
                 ^
foo.cpp:9:17: error: no matching function for call to
'end(std::vector<std::pair<unsigned int, unsigned int>*>*&)'
In file included from .../include/c++/5.0.0/vector:66:0,
                 from foo.cpp:1:
.../include/c++/5.0.0/bits/range_access.h:97:5: note: candidate: template<class
_Tp, long unsigned int _Nm> _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^
.../include/c++/5.0.0/bits/range_access.h:97:5: note:   template argument
deduction/substitution failed:
foo.cpp:9:17: note:   mismatched types '_Tp [_Nm]' and
'std::vector<std::pair<unsigned int, unsigned int>*>*'
   for (auto i : foo)
                 ^
In file included from .../include/c++/5.0.0/vector:66:0,
                 from foo.cpp:1:
.../include/c++/5.0.0/bits/range_access.h:78:5: note: candidate: template<class
_Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^
.../include/c++/5.0.0/bits/range_access.h:78:5: note:   template argument
deduction/substitution failed:
.../include/c++/5.0.0/bits/range_access.h: In substitution of 'template<class
_Container> decltype (__cont.end()) std::end(const _Container&) [with
_Container = std::vector<std::pair<unsigned int, unsigned int>*>*]':
foo.cpp:9:17:   required from here
.../include/c++/5.0.0/bits/range_access.h:78:5: error: request for member 'end'
in '__cont', which is of pointer type 'std::vector<std::pair<unsigned int,
unsigned int>*>* const' (maybe you meant to use '->' ?)
.../include/c++/5.0.0/bits/range_access.h:68:5: note: candidate: template<class
_Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^
.../include/c++/5.0.0/bits/range_access.h:68:5: note:   template argument
deduction/substitution failed:
.../include/c++/5.0.0/bits/range_access.h: In substitution of 'template<class
_Container> decltype (__cont.end()) std::end(_Container&) [with _Container =
std::vector<std::pair<unsigned int, unsigned int>*>*]':
foo.cpp:9:17:   required from here
.../include/c++/5.0.0/bits/range_access.h:68:5: error: request for member 'end'
in '__cont', which is of pointer type 'std::vector<std::pair<unsigned int,
unsigned int>*>*' (maybe you meant to use '->' ?)
In file included from .../include/c++/5.0.0/bits/stl_vector.h:63:0,
                 from .../include/c++/5.0.0/vector:64,
                 from foo.cpp:1:
.../include/c++/5.0.0/initializer_list:99:5: note: candidate: template<class
_Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^
.../include/c++/5.0.0/initializer_list:99:5: note:   template argument
deduction/substitution failed:
foo.cpp:9:17: note:   mismatched types 'std::initializer_list<_Tp>' and
'std::vector<std::pair<unsigned int, unsigned int>*>*'
   for (auto i : foo)
                 ^


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]