Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s |
Argyrios Kyrtzidis | 12179bc | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2 | |
| 3 | void f() { |
| 4 | typedef int T; |
| 5 | int x, *px; |
| 6 | |
| 7 | // Type id. |
Sebastian Redl | 9f831db | 2009-07-25 15:41:38 +0000 | [diff] [blame] | 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 ()'}} |
Argyrios Kyrtzidis | 12179bc | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 11 | |
| 12 | // Expression. |
| 13 | x = (T()); |
| 14 | x = (T())/x; |
Argyrios Kyrtzidis | 4a6dad6 | 2009-05-22 23:05:39 +0000 | [diff] [blame] | 15 | |
| 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 Friedman | cf7530f | 2009-05-25 19:41:42 +0000 | [diff] [blame] | 19 | |
| 20 | // Special case: empty parens is a call, not an expression |
| 21 | struct S{int operator()();}; |
| 22 | (S())(); |
| 23 | |
Richard Smith | 4378568 | 2016-02-03 02:58:20 +0000 | [diff] [blame] | 24 | // 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 Smith | 7b4df3b | 2016-02-03 18:48:43 +0000 | [diff] [blame] | 31 | int q = (int)++(x); |
Argyrios Kyrtzidis | 12179bc | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 32 | } |
John McCall | e2ade28 | 2009-12-19 00:35:18 +0000 | [diff] [blame] | 33 | |
| 34 | // Make sure we do tentative parsing correctly in conditions. |
| 35 | typedef int type; |
| 36 | struct rec { rec(int); }; |
| 37 | |
| 38 | namespace ns { |
| 39 | typedef int type; |
| 40 | struct rec { rec(int); }; |
| 41 | } |
| 42 | |
| 43 | struct cls { |
| 44 | typedef int type; |
| 45 | struct rec { rec(int); }; |
| 46 | }; |
| 47 | |
| 48 | struct result { |
| 49 | template <class T> result(T); |
| 50 | bool check(); |
| 51 | }; |
| 52 | |
| 53 | void 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 | |