[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / cxx-ambig-paren-expr.cpp
blobcc509f7b059f30a4859609f4aed8aea419b28d43
1 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
3 void f() {
4 typedef int T;
5 int x, *px;
7 // Type id.
8 (T())x; // expected-error {{cast from 'int' to 'T ()'}}
9 (T())+x; // expected-error {{cast from 'int' to 'T ()'}}
10 (T())*px; // expected-error {{cast from 'int' to 'T ()'}}
12 // Expression.
13 x = (T());
14 x = (T())/x;
16 typedef int *PT;
17 // Make sure stuff inside the parens are parsed only once (only one warning).
18 x = (PT()[(int){1}]); // expected-warning {{compound literals}}
20 // Special case: empty parens is a call, not an expression
21 struct S{int operator()();};
22 (S())();
24 // Special case: "++" is postfix here, not prefix
25 (S())++; // expected-error {{cannot increment value of type 'S'}}
27 struct X { int &operator++(int); X operator[](int); int &operator++(); };
28 int &postfix_incr = (X()[3])++;
29 (X())++ ++; // ok, not a C-style cast
30 (X())++ ++X(); // expected-error {{C-style cast from 'int' to 'X ()'}}
31 int q = (int)++(x);
34 // Make sure we do tentative parsing correctly in conditions.
35 typedef int type;
36 struct rec { rec(int); };
38 namespace ns {
39 typedef int type;
40 struct rec { rec(int); };
43 struct cls {
44 typedef int type;
45 struct rec { rec(int); };
48 struct result {
49 template <class T> result(T);
50 bool check();
53 void test(int i) {
54 if (result((cls::type) i).check())
55 return;
57 if (result((ns::type) i).check())
58 return;
60 if (result((::type) i).check())
61 return;
63 if (result((cls::rec) i).check())
64 return;
66 if (result((ns::rec) i).check())
67 return;
69 if (result((::rec) i).check())
70 return;