teak-llvm/clang/test/Parser/colon-colon-parentheses.cpp
Reid Kleckner 6c03cfb091 Remove special error recovery for ::(id)
The code pattern used to implement the token rewriting hack doesn't
interact well with token caching in the pre-processor. As a result,
clang would crash on 'int f(::(id));' while doing a tenative parse of
the contents of the outer parentheses. The original code from PR11852
still doesn't crash the compiler.

This error recovery also often does the wrong thing with member function
pointers. The test case from the original PR doesn't recover the right
way either:
  void S::(*pf)() = S::f; // should be 'void (S::*pf)()'

Instead we were recovering as 'void S::*pf()', which is still wrong.

If we still think that users mistakenly parenthesize identifiers in
nested name specifiers, we should change clang to intentionally parse
that form with an error, rather than doing a token rewrite.

Fixes PR26623, but I think there will be many more bugs like this around
token rewriting in the parser.

Reviewers: rsmith, rtrieu

Differential Revision: https://reviews.llvm.org/D25882

llvm-svn: 289273
2016-12-09 21:10:43 +00:00

37 lines
1.2 KiB
C++

// RUN: %clang_cc1 %s -verify -fno-spell-checking
struct S { static int a,b,c;};
int S::(a); // expected-error{{expected unqualified-id}}
int S::(b; // expected-error{{expected unqualified-id}}
);
int S::c;
int S::(*d); // expected-error{{expected unqualified-id}}
int S::(*e; // expected-error{{expected unqualified-id}}
);
int S::*f;
int g = S::(a); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'a'}}
int h = S::(b; // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'b'}}
);
int i = S::c;
void foo() {
int a;
a = ::(g); // expected-error{{expected unqualified-id}}
a = ::(h; // expected-error{{expected unqualified-id}}
a = ::i;
}
// The following tests used to be crash bugs.
// PR21815
// expected-error@+2{{C++ requires a type specifier for all declarations}}
// expected-error@+1{{expected unqualified-id}}
a (::( ));
::((c )); // expected-error{{expected unqualified-id}}
// PR26623
int f1(::(B) p); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'B'}}
int f2(::S::(C) p); // expected-error {{expected unqualified-id}} expected-error {{use of undeclared identifier 'C'}}