[Bug c++/68842] Better error output when template needed before dependent name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68842 Andrew Pinski changed: What|Removed |Added CC||soko.slav at yandex dot ru --- Comment #4 from Andrew Pinski --- *** Bug 90495 has been marked as a duplicate of this bug. ***
[Bug c++/68842] Better error output when template needed before dependent name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68842 Jonathan Wakely changed: What|Removed |Added Keywords||diagnostic Status|UNCONFIRMED |NEW Last reconfirmed||2015-12-11 Ever confirmed|0 |1 --- Comment #1 from Jonathan Wakely --- N.B. GCC 4.8 is no longer supported and the branch is closed, but the diagnostic is the same in current releases, and I agree a "fix-it" hint would be better than the current error. Clang gives a different error, which IMHO is even less helpful despite trying to give a fix-it hint: tt.cc:15:5: error: reference to non-static member function must be called t.do_nothing(0); ~~^~ tt.cc:20:3: note: in instantiation of function template specialization 'do_test<2>' requested here do_test<2>(); ^ tt.cc:5:8: note: possible target for call void do_nothing(int value) ^ 1 error generated.
[Bug c++/68842] Better error output when template needed before dependent name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68842 --- Comment #2 from Jonathan Wakely --- And interestingly EDG compiles it without error!
[Bug c++/68842] Better error output when template needed before dependent name
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68842 --- Comment #3 from Jonathan Wakely --- --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4907,8 +4907,13 @@ cp_build_binary_op (location_t location, if (!result_type) { if (complain & tf_error) - error ("invalid operands of types %qT and %qT to binary %qO", - TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code); +{ + error ("invalid operands of types %qT and %qT to binary %qO", + TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code); + if (code == LT_EXPR) +inform (input_location, "use the keyword % before the " +"name of a member template belonging to a dependent type"); +} return error_mark_node; } This patch adds the following line after the error: tt.cc:15:15: note: use the keyword ‘template’ before the name of a member template belonging to a dependent type I don't know how to make it only issue that note when the LHS is one of foo.bar, foo->bar, or foo::bar.