[cfe-commits] [PATCH] PR10053 Improved two-stage lookup diagnostic

Douglas Gregor dgregor at apple.com
Sat Jun 4 20:16:50 PDT 2011


On Jun 4, 2011, at 1:37 PM, Richard Smith wrote:

> Hi,
> 
> The attached patch improves our error recovery when handling code which
> some versions of gcc incorrectly accept, due to an incomplete
> implementation of two-stage name lookup.
> 
> This example from the compatibility section on the www:
> 
> template <typename T> T Squared(T x) {
>  return Multiply(x, x);
> }
> 
> int Multiply(int x, int y) {
>  return x * y;
> }
> 
> int main() {
>  Squared(5);
> }
> 
> Now produces the following diagnostics:
> 
> my_file.cpp:2:10: error: use of undeclared identifier 'Multiply'
>  return Multiply(x, x);
>         ^
> my_file.cpp:10:3: note: in instantiation of function template
> specialization 'Squared<int>' requested here
>  Squared(5);
>  ^
> my_file.cpp:5:5: note: viable function not candidate: declared after
> template was defined and not in an associated namespace
> int Multiply(int x, int y) {
>    ^
> 
> This patch only diagnoses normal unqualified names; diagnostics for names
> with scope specifiers and for overloaded operators are not similarly
> improved.


The code looks good, but I think the diagnostic wording could be improved considerably. The error message should say what the problem is, and the note should suggest the solution. For example:

	error: call to function 'Multiply' that is neither visible in the template definition nor found by argument dependent lookup

	note: 'Multiply' should be declared prior to the call site or in the namespace of one of its arguments

Thanks for tackling this!

	- Doug



More information about the cfe-commits mailing list