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