blob: cc509f7b059f30a4859609f4aed8aea419b28d43 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
Argyrios Kyrtzidis12179bc2009-05-22 10:24:42 +00002
3void f() {
4 typedef int T;
5 int x, *px;
6
7 // Type id.
Sebastian Redl9f831db2009-07-25 15:41:38 +00008 (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 ()'}}
Argyrios Kyrtzidis12179bc2009-05-22 10:24:42 +000011
12 // Expression.
13 x = (T());
14 x = (T())/x;
Argyrios Kyrtzidis4a6dad62009-05-22 23:05:39 +000015
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}}
Eli Friedmancf7530f2009-05-25 19:41:42 +000019
20 // Special case: empty parens is a call, not an expression
21 struct S{int operator()();};
22 (S())();
23
Richard Smith43785682016-02-03 02:58:20 +000024 // Special case: "++" is postfix here, not prefix
25 (S())++; // expected-error {{cannot increment value of type 'S'}}
26
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 ()'}}
Richard Smith7b4df3b2016-02-03 18:48:43 +000031 int q = (int)++(x);
Argyrios Kyrtzidis12179bc2009-05-22 10:24:42 +000032}
John McCalle2ade282009-12-19 00:35:18 +000033
34// Make sure we do tentative parsing correctly in conditions.
35typedef int type;
36struct rec { rec(int); };
37
38namespace ns {
39 typedef int type;
40 struct rec { rec(int); };
41}
42
43struct cls {
44 typedef int type;
45 struct rec { rec(int); };
46};
47
48struct result {
49 template <class T> result(T);
50 bool check();
51};
52
53void test(int i) {
54 if (result((cls::type) i).check())
55 return;
56
57 if (result((ns::type) i).check())
58 return;
59
60 if (result((::type) i).check())
61 return;
62
63 if (result((cls::rec) i).check())
64 return;
65
66 if (result((ns::rec) i).check())
67 return;
68
69 if (result((::rec) i).check())
70 return;
71}
72