xref: /llvm-project/clang/test/Parser/cxx-keyword-identifiers.cpp (revision 2cb2cd242ca08d0bbd2a51a41f1317442e5414fc)
1625acd8fSHaojian Wu // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2625acd8fSHaojian Wu 
3625acd8fSHaojian Wu 
foo1(int case,int throw,int y)4625acd8fSHaojian Wu int foo1(int case, int throw, int y) { // expected-error {{invalid parameter name: 'case' is a keyword}} \
5625acd8fSHaojian Wu                                           expected-error {{invalid}}
6625acd8fSHaojian Wu   // Trailing parameters should be recovered.
7625acd8fSHaojian Wu   y = 1;
8625acd8fSHaojian Wu }
9625acd8fSHaojian Wu 
10625acd8fSHaojian Wu int foo2(int case = 1); // expected-error {{invalid parameter}}
11625acd8fSHaojian Wu int foo3(int const); // ok: without parameter name.
12625acd8fSHaojian Wu // ok: override has special meaning when used after method functions. it can be
13625acd8fSHaojian Wu // used as name.
14625acd8fSHaojian Wu int foo4(int override);
15625acd8fSHaojian Wu int foo5(int x const); // expected-error {{expected ')'}} expected-note {{to match this '('}}
16625acd8fSHaojian Wu // FIXME: bad recovery on the case below, "invalid parameter" is desired, the
17625acd8fSHaojian Wu // followon diagnostics should be suppressed.
18625acd8fSHaojian Wu int foo6(int case __attribute((weak))); // expected-error {{invalid parameter}}  \
19625acd8fSHaojian Wu                                         // expected-error {{expected ')'}} expected-note {{to match this '('}}
20625acd8fSHaojian Wu 
test()21625acd8fSHaojian Wu void test() {
22625acd8fSHaojian Wu   // FIXME: we shoud improve the dianostics for the following cases.
23625acd8fSHaojian Wu   int case; // expected-error {{expected unqualified-id}}
24625acd8fSHaojian Wu   struct X {
25625acd8fSHaojian Wu     int case; // expected-error {{expected member name or ';'}}
26625acd8fSHaojian Wu   };
27625acd8fSHaojian Wu }
28d026f2f7SKadir Cetinkaya struct Foo {
29*2cb2cd24SAaron Ballman   void bar(*decltype(1) aux); // expected-error {{a type specifier is required for all declarations}}. \
30d026f2f7SKadir Cetinkaya                                  // expected-error {{expected ')'}} expected-note {{to match this '('}}
31d026f2f7SKadir Cetinkaya };
32