[Bug c++/50462] poor diagnostics for missing parenthesis in call to method
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Apr 23 11:49:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50462
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think the original example in this bug is the same as PR 77711 comment 2. It
can be reduced to:
struct ostream { };
void operator<<(ostream, int) { }
void operator<<(ostream, void*) { }
void operator<<(ostream, char*) { }
struct V
{
int size() { return 0; };
};
void print(V v)
{ ostream() << v.size; }
Now GCC's output fits on a single page:
50462.cc: In function 'void print(V)':
50462.cc:14:13: error: no match for 'operator<<' (operand types are 'ostream'
and '<unresolved overloaded function type>')
{ ostream() << v.size; }
~~~~~~~~~~^~~~~~~~~
50462.cc:3:6: note: candidate: void operator<<(ostream, int)
void operator<<(ostream, int) { }
^~~~~~~~
50462.cc:3:6: note: no known conversion for argument 2 from '<unresolved
overloaded function type>' to 'int'
50462.cc:4:6: note: candidate: void operator<<(ostream, void*)
void operator<<(ostream, void*) { }
^~~~~~~~
50462.cc:4:6: note: no known conversion for argument 2 from '<unresolved
overloaded function type>' to 'void*'
50462.cc:5:6: note: candidate: void operator<<(ostream, char*)
void operator<<(ostream, char*) { }
^~~~~~~~
50462.cc:5:6: note: no known conversion for argument 2 from '<unresolved
overloaded function type>' to 'char*'
But Clang still does better, not bothering to perform overload resolution
hoping v.size will turn into something meaningful. Clang just says:
50462.cc:10:18: error: reference to non-static member function must be called;
did you mean to call it with no arguments?
{ std::cout << v.size; }
~~^~~~
()
50462.cc:5:6: note: possible target for call
int size() {};
^
50462.cc:6:6: note: possible target for call
int size() const {};
^
1 error generated.
So it doesn't bother telling us that every overload of operator<< is unusable
for a nonsense expression, which is much better.
EDG says:
"50462.cc", line 14: error: a pointer to a bound function may only be used to
call the function
{ ostream() << v.size; }
^
1 error detected in the compilation of "50462.cc".
This is a little cryptic and suggests there might be some non-standard
extension confusing matters.
More information about the Gcc-bugs
mailing list