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

Richard Smith richard at metafoo.co.uk
Sat Jun 4 13:37:58 PDT 2011


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.

OK to commit?

Richard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr10053.diff
Type: text/x-patch
Size: 10017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110604/991b42eb/attachment.bin>


More information about the cfe-commits mailing list