Files
clang-p2996/clang/test/Parser/cxx-keyword-identifiers.cpp
Haojian Wu 625acd8f68 [Parser] Improve diagnostic and error recovery when C++ keywords are used as identifiers.
Summary:
Previously, clang emitted a less-usefull diagnostic and didnt recover
well when the keywords is used as identifier in function paramter.

```
void foo(int case, int x); // previously we drop all parameters after
`int case`.
```

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77633
2020-04-08 15:15:33 +02:00

28 lines
1.1 KiB
C++

// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
int foo1(int case, int throw, int y) { // expected-error {{invalid parameter name: 'case' is a keyword}} \
expected-error {{invalid}}
// Trailing parameters should be recovered.
y = 1;
}
int foo2(int case = 1); // expected-error {{invalid parameter}}
int foo3(int const); // ok: without parameter name.
// ok: override has special meaning when used after method functions. it can be
// used as name.
int foo4(int override);
int foo5(int x const); // expected-error {{expected ')'}} expected-note {{to match this '('}}
// FIXME: bad recovery on the case below, "invalid parameter" is desired, the
// followon diagnostics should be suppressed.
int foo6(int case __attribute((weak))); // expected-error {{invalid parameter}} \
// expected-error {{expected ')'}} expected-note {{to match this '('}}
void test() {
// FIXME: we shoud improve the dianostics for the following cases.
int case; // expected-error {{expected unqualified-id}}
struct X {
int case; // expected-error {{expected member name or ';'}}
};
}