[PATCH,c++] fix PR 45330, suggest alternatives for failed name lookups

Mark Mitchell mark@codesourcery.com
Wed Nov 17 03:52:00 GMT 2010


On 11/10/2010 10:13 AM, Nathan Froyd wrote:

> and the perceived problem is that GCC should suggest `N::foo' for the
> unqualified `foo' in `bar'.  The below patch does just that: when name
> lookup fails, we grovel through all known namespaces for potential
> matches and suggest them to the user.

I thought about this for a while from two angles:

(a) Will that be incredibly slow?
(b) Is there any reasonable way to limit the set of namespaces searched?

I decided (a) doesn't really matter; we're issuing an error, worst-case
we probably have a few thousand namespaces, should be OK.

For (b), the obvious thing would be to limit to parents and children
(but not siblings) of current namespaces.  So, for:

  namespace A {
    namespace B { }
    namespace C {
      namespace D { }
    }
  }

if the error is inside C, look in D, but not B.  But, that's probably
dumb; I don't really believe that this is more likely than B.  So, it
would only be a useful heuristic if we decided we really need to prune
the search.  And, of course, we could refuse to search more than 100
namespaces, if we wanted.  I think you should probably add a --param
(max-namespace-for-diagnostic-help) for that, and start with 1000 as the
default, just to ensure sanity?

> I didn't include a testcase, as the testcase tweaks indicated there are
> a number of testcases testing similar things.

OK, but can you make at least one of the testcases check for the proper
alternative name?  (Right now, it looks like you're just checking the
line numbers.)

Thank you,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list