Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 1 | // Header for PCH test cxx_exprs.cpp |
| 2 | |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 3 | |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 4 | // CXXStaticCastExpr |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 5 | typedef __typeof__(static_cast<void *>(0)) static_cast_result; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 6 | |
| 7 | // CXXDynamicCastExpr |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 8 | struct Base { Base(int); virtual void f(int x = 492); ~Base(); }; |
| 9 | struct Derived : Base { Derived(); void g(); }; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 10 | Base *base_ptr; |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 11 | typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 12 | |
| 13 | // CXXReinterpretCastExpr |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 14 | typedef __typeof__(reinterpret_cast<void *>(0)) reinterpret_cast_result; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 15 | |
| 16 | // CXXConstCastExpr |
| 17 | const char *const_char_ptr_value; |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 18 | typedef __typeof__(const_cast<char *>(const_char_ptr_value)) const_cast_result; |
Sam Weinig | ce757a7 | 2010-01-16 21:21:01 +0000 | [diff] [blame] | 19 | |
| 20 | // CXXFunctionalCastExpr |
| 21 | int int_value; |
Sam Weinig | eb7f961 | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 22 | typedef __typeof__(double(int_value)) functional_cast_result; |
| 23 | |
| 24 | // CXXBoolLiteralExpr |
| 25 | typedef __typeof__(true) bool_literal_result; |
| 26 | const bool true_value = true; |
| 27 | const bool false_value = false; |
| 28 | |
| 29 | // CXXNullPtrLiteralExpr |
| 30 | typedef __typeof__(nullptr) cxx_null_ptr_result; |
Chris Lattner | 1817bd4 | 2010-05-09 05:36:05 +0000 | [diff] [blame] | 31 | |
| 32 | void foo(Derived *P) { |
| 33 | // CXXMemberCallExpr |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 34 | P->f(12); |
Chris Lattner | 14ab24f | 2010-05-09 06:03:39 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | |
| 38 | // FIXME: This is a hack until <typeinfo> works completely. |
| 39 | namespace std { |
| 40 | class type_info {}; |
| 41 | } |
| 42 | |
| 43 | // CXXTypeidExpr - Both expr and type forms. |
| 44 | typedef __typeof__(typeid(int))* typeid_result1; |
| 45 | typedef __typeof__(typeid(2))* typeid_result2; |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 46 | |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 47 | Derived foo(); |
| 48 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 49 | Derived::Derived() : Base(4) { |
| 50 | } |
| 51 | |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 52 | void Derived::g() { |
| 53 | // CXXThisExpr |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 54 | f(2); // Implicit |
| 55 | this->f(1); // Explicit |
Chris Lattner | 2fbdfcd | 2010-05-09 06:15:05 +0000 | [diff] [blame] | 56 | |
| 57 | // CXXThrowExpr |
| 58 | throw; |
| 59 | throw 42; |
Chris Lattner | 030854b | 2010-05-09 06:40:08 +0000 | [diff] [blame] | 60 | |
| 61 | // CXXDefaultArgExpr |
| 62 | f(); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 63 | |
| 64 | const Derived &X = foo(); |
| 65 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 66 | // FIXME: How do I make a CXXBindReferenceExpr, CXXConstructExpr? |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 67 | |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 68 | int A = int(0.5); // CXXFunctionalCastExpr |
| 69 | A = int(); // CXXZeroInitValueExpr |
| 70 | |
Argyrios Kyrtzidis | 95fc98c | 2010-06-22 17:07:59 +0000 | [diff] [blame] | 71 | Base *b = new Base(4); // CXXNewExpr |
| 72 | delete b; // CXXDeleteExpr |
Chris Lattner | 5921863 | 2010-05-10 01:22:27 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | // FIXME: The comment on CXXTemporaryObjectExpr is broken, this doesn't make |
| 77 | // one. |
| 78 | struct CtorStruct { CtorStruct(int, float); }; |
| 79 | |
| 80 | CtorStruct create_CtorStruct() { |
| 81 | return CtorStruct(1, 3.14f); // CXXTemporaryObjectExpr |
| 82 | }; |
| 83 | |