Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s |
Argyrios Kyrtzidis | f58f45e | 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 | 9cc11e7 | 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 | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 11 | |
| 12 | // Expression. |
| 13 | x = (T()); |
| 14 | x = (T())/x; |
Argyrios Kyrtzidis | f303e8a | 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 | b53f08a | 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 | |
| 24 | // FIXME: Special case: "++" is postfix here, not prefix |
| 25 | // (S())++; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 26 | } |
John McCall | ae03cb5 | 2009-12-19 00:35:18 +0000 | [diff] [blame] | 27 | |
| 28 | // Make sure we do tentative parsing correctly in conditions. |
| 29 | typedef int type; |
| 30 | struct rec { rec(int); }; |
| 31 | |
| 32 | namespace ns { |
| 33 | typedef int type; |
| 34 | struct rec { rec(int); }; |
| 35 | } |
| 36 | |
| 37 | struct cls { |
| 38 | typedef int type; |
| 39 | struct rec { rec(int); }; |
| 40 | }; |
| 41 | |
| 42 | struct result { |
| 43 | template <class T> result(T); |
| 44 | bool check(); |
| 45 | }; |
| 46 | |
| 47 | void test(int i) { |
| 48 | if (result((cls::type) i).check()) |
| 49 | return; |
| 50 | |
| 51 | if (result((ns::type) i).check()) |
| 52 | return; |
| 53 | |
| 54 | if (result((::type) i).check()) |
| 55 | return; |
| 56 | |
| 57 | if (result((cls::rec) i).check()) |
| 58 | return; |
| 59 | |
| 60 | if (result((ns::rec) i).check()) |
| 61 | return; |
| 62 | |
| 63 | if (result((::rec) i).check()) |
| 64 | return; |
| 65 | } |
| 66 | |