blob: 1535b009725137370eccdcbca1e079bf7742ea96 [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 ()'}}
Argyrios Kyrtzidis12179bc2009-05-22 10:24:42 +000031}
John McCalle2ade282009-12-19 00:35:18 +000032
33// Make sure we do tentative parsing correctly in conditions.
34typedef int type;
35struct rec { rec(int); };
36
37namespace ns {
38 typedef int type;
39 struct rec { rec(int); };
40}
41
42struct cls {
43 typedef int type;
44 struct rec { rec(int); };
45};
46
47struct result {
48 template <class T> result(T);
49 bool check();
50};
51
52void test(int i) {
53 if (result((cls::type) i).check())
54 return;
55
56 if (result((ns::type) i).check())
57 return;
58
59 if (result((::type) i).check())
60 return;
61
62 if (result((cls::rec) i).check())
63 return;
64
65 if (result((ns::rec) i).check())
66 return;
67
68 if (result((::rec) i).check())
69 return;
70}
71