xref: /llvm-project/clang/test/Parser/expressions.cpp (revision 4d1b7e9820ee9c87541619ce4dd41e92dc43cd9c)
1*4d1b7e98SRichard Smith // RUN: %clang_cc1 -std=c++2a -verify %s
2*4d1b7e98SRichard Smith 
3*4d1b7e98SRichard Smith void *operator new(__SIZE_TYPE__, void*);
4*4d1b7e98SRichard Smith 
5*4d1b7e98SRichard Smith // Check that we give a good diagnostic for an attempt to use a postfix
6*4d1b7e98SRichard Smith // operator after a unary-expression.
7*4d1b7e98SRichard Smith namespace postfix_after_unary {
8*4d1b7e98SRichard Smith   struct A { int n; };
9*4d1b7e98SRichard Smith   int &a = new A->n; // expected-error {{expression cannot be followed by a postfix '->' operator; add parentheses}}
10*4d1b7e98SRichard Smith 
11*4d1b7e98SRichard Smith   struct B { B(int); int operator()(int); };
12*4d1b7e98SRichard Smith   int n = new (0) (B) (int()) (int()); // expected-error {{cannot be followed by a postfix '(}} expected-error {{not a function or function pointer}}
13*4d1b7e98SRichard Smith 
14*4d1b7e98SRichard Smith   char x = sizeof(int)["hello"]; // expected-error {{cannot be followed by a postfix '[}}
15*4d1b7e98SRichard Smith   char y = alignof(int)["hello"]; // expected-error {{cannot be followed by a postfix '[}}
16*4d1b7e98SRichard Smith   char z = noexcept(0)["hello"]; // expected-error {{cannot be followed by a postfix '[}}
17*4d1b7e98SRichard Smith   char w = requires { x == x; }["ny"]; // expected-error {{cannot be followed by a postfix '[}}
18*4d1b7e98SRichard Smith 
f()19*4d1b7e98SRichard Smith   int f() {
20*4d1b7e98SRichard Smith   label:
21*4d1b7e98SRichard Smith     return &&label->n; // expected-error {{cannot be followed by a postfix}} expected-error {{not a structure or union}}
22*4d1b7e98SRichard Smith   }
23*4d1b7e98SRichard Smith 
24*4d1b7e98SRichard Smith   char k = sizeof(int) // expected-error {{expected ';'}}
25*4d1b7e98SRichard Smith   [[noreturn]] void g();
26*4d1b7e98SRichard Smith }
27*4d1b7e98SRichard Smith 
28*4d1b7e98SRichard Smith // Check that we do parse postfix-expression suffixes after some more unusual
29*4d1b7e98SRichard Smith // kinds of postfix-expressions (null literals and builtin calls).
30*4d1b7e98SRichard Smith namespace unusual_primary_exprs {
31*4d1b7e98SRichard Smith   int a = nullptr["foo"]; // expected-error {{array subscript is not an integer}}
32*4d1b7e98SRichard Smith   int b = __builtin_COLUMN()["sufficiently long string constant"];
33*4d1b7e98SRichard Smith   int c = __builtin_available(*)["ny"];
34*4d1b7e98SRichard Smith   static_assert(__null["foo"] == 'f'); // FIXME: Warn about converting __null to integer in array subscripting.
35*4d1b7e98SRichard Smith   static_assert(__is_standard_layout(int)["ny"] == 'y');
36*4d1b7e98SRichard Smith   static_assert(__array_rank(int[1][2])["0123"] == '2');
37*4d1b7e98SRichard Smith   static_assert(__is_lvalue_expr(a)["ny"] == 'y');
38*4d1b7e98SRichard Smith }
39