llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Unclosed namespace causes cryptic errors

Open amccarth-google opened this issue 11 years ago • 1 comments

Bugzilla Link 25303
Resolution WONTFIX
Resolved on Oct 23, 2015 21:46
Version unspecified
OS Windows NT
CC @DougGregor,@zygoloid

Extended Description

consider: namespace Foo {

namespace Bar { void thud(); } void qux() { ::Bar::thud(); }

clang generates the following diagnostics: error: no member named 'Bar' in the global namespace; did you mean simply 'Bar'? ::Bar::thud(); ^~~~~ Bar note: 'Bar' declared here namespace Bar { void thud(); } ^ error: expected '}' } ^ note: to match this '{' namespace Foo { ^ 2 errors generated.

It would have been nicer to recover by inserting a '}' before 'namespace Bar'.

amccarth-google avatar Oct 24 '15 00:10 amccarth-google

It would have been nicer to recover by inserting a '}' before 'namespace Bar'.

That would require extreme lookahead or reverting a lot of parser state, both of which are not feasible. Nothing is obviously wrong here until we reach the ill-formed call to ::Bar::thud, and that error is indistinguishable from the nested name specifier on the call being wrong, which is what we say.

I don't think this is feasible for us to improve, unless you have some specific suggestion for how we would detect the problem.