https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71982
Bug ID: 71982 Summary: Wrong error and note range with macro Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: denis.campredon at gmail dot com Target Milestone: --- Created attachment 38956 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38956&action=edit Reproducer to the bug Compiling the attached file with `g++ ./bug.cpp' show an erroneous error range: ./bug.cpp: In instantiation of ‘bool operator==(const A<T>&, const A<T>&) [with T = const B]’: ./bug.cpp:25:30: required from here ./bug.cpp:1:34: error: no match for ‘operator==’ (operand types are ‘const B’ and ‘const B’) #define MACRO(left, right) *left == *right ~~~~~~^~~~~~~~~ template <typename T> ~~~~~~~~~~~~~~~~~~~~~ struct A { ~~~~~~~~~~ T *a; ~~~~~ T* get() const; ~~~~~~~~~~~~~~~ }; ~~ template <typename T> ~~~~~~~~~~~~~~~~~~~~~ bool operator==(const A<T>& left, const A<T>& right) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { ~ T* _left = left.get(); ~~~~~~~~~~~~~~~~~~~~~~ T* _right = right.get(); ~~~~~~~~~~~~~~~~~~~~~~~~ return MACRO(_left, _right); ~~~~~~~~~~~~~~~~~~~~~ ./bug.cpp:15:10: note: in expansion of macro ‘MACRO’ return MACRO(_left, _right); ^~~~~ ./bug.cpp:10:6: note: candidate: template<class T> bool operator==(const A<T>&, const A<T>&) bool operator==(const A<T>& left, const A<T>& right) ^~~~~~~~ ./bug.cpp:10:6: note: template argument deduction/substitution failed: ./bug.cpp:1:34: note: ‘const B’ is not derived from ‘const A<T>’ #define MACRO(left, right) *left == *right ~~~~~~^~~~~~~~~ template <typename T> ~~~~~~~~~~~~~~~~~~~~~ struct A { ~~~~~~~~~~ T *a; ~~~~~ T* get() const; ~~~~~~~~~~~~~~~ }; ~~ template <typename T> ~~~~~~~~~~~~~~~~~~~~~ bool operator==(const A<T>& left, const A<T>& right) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { ~ T* _left = left.get(); ~~~~~~~~~~~~~~~~~~~~~~ T* _right = right.get(); ~~~~~~~~~~~~~~~~~~~~~~~~ return MACRO(_left, _right); ~~~~~~~~~~~~~~~~~~~~~ ./bug.cpp:15:10: note: in expansion of macro ‘MACRO’ return MACRO(_left, _right); ^~~~~ ./bug.cpp:24:6: note: candidate: bool operator==(C&, C&) bool operator==(C& left, C& right) { ^~~~~~~~ ./bug.cpp:24:6: note: no known conversion for argument 1 from ‘const B’ to ‘C&’ -------------------- compiled with gcc version 7.0.0 20160716 (experimental) (GCC)