1*f4a2713aSLionel Sambuc // Header for PCH test cxx_exprs.cpp 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuc // CXXStaticCastExpr 5*f4a2713aSLionel Sambuc typedef __typeof__(static_cast<void *>(0)) static_cast_result; 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc // CXXDynamicCastExpr 8*f4a2713aSLionel Sambuc struct Base { Base(int); virtual void f(int x = 492); ~Base(); }; 9*f4a2713aSLionel Sambuc struct Derived : Base { Derived(); void g(); }; 10*f4a2713aSLionel Sambuc Base *base_ptr; 11*f4a2713aSLionel Sambuc typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result; 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc // CXXReinterpretCastExpr 14*f4a2713aSLionel Sambuc typedef __typeof__(reinterpret_cast<void *>(0)) reinterpret_cast_result; 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc // CXXConstCastExpr 17*f4a2713aSLionel Sambuc const char *const_char_ptr_value; 18*f4a2713aSLionel Sambuc typedef __typeof__(const_cast<char *>(const_char_ptr_value)) const_cast_result; 19*f4a2713aSLionel Sambuc 20*f4a2713aSLionel Sambuc // CXXFunctionalCastExpr 21*f4a2713aSLionel Sambuc int int_value; 22*f4a2713aSLionel Sambuc typedef __typeof__(double(int_value)) functional_cast_result; 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc // CXXBoolLiteralExpr 25*f4a2713aSLionel Sambuc typedef __typeof__(true) bool_literal_result; 26*f4a2713aSLionel Sambuc const bool true_value = true; 27*f4a2713aSLionel Sambuc const bool false_value = false; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc // CXXNullPtrLiteralExpr 30*f4a2713aSLionel Sambuc typedef __typeof__(nullptr) cxx_null_ptr_result; 31*f4a2713aSLionel Sambuc foo(Derived * P)32*f4a2713aSLionel Sambucvoid foo(Derived *P) { 33*f4a2713aSLionel Sambuc // CXXMemberCallExpr 34*f4a2713aSLionel Sambuc P->f(12); 35*f4a2713aSLionel Sambuc } 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc 38*f4a2713aSLionel Sambuc // FIXME: This is a hack until <typeinfo> works completely. 39*f4a2713aSLionel Sambuc namespace std { 40*f4a2713aSLionel Sambuc class type_info {}; 41*f4a2713aSLionel Sambuc } 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc // CXXTypeidExpr - Both expr and type forms. 44*f4a2713aSLionel Sambuc typedef __typeof__(typeid(int))* typeid_result1; 45*f4a2713aSLionel Sambuc typedef __typeof__(typeid(2))* typeid_result2; 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc Derived foo(); 48*f4a2713aSLionel Sambuc Derived()49*f4a2713aSLionel SambucDerived::Derived() : Base(4) { 50*f4a2713aSLionel Sambuc } 51*f4a2713aSLionel Sambuc g()52*f4a2713aSLionel Sambucvoid Derived::g() { 53*f4a2713aSLionel Sambuc // CXXThisExpr 54*f4a2713aSLionel Sambuc f(2); // Implicit 55*f4a2713aSLionel Sambuc this->f(1); // Explicit 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc // CXXThrowExpr 58*f4a2713aSLionel Sambuc throw; 59*f4a2713aSLionel Sambuc throw 42; 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc // CXXDefaultArgExpr 62*f4a2713aSLionel Sambuc f(); 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc const Derived &X = foo(); 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc // FIXME: How do I make a CXXBindReferenceExpr, CXXConstructExpr? 67*f4a2713aSLionel Sambuc 68*f4a2713aSLionel Sambuc int A = int(0.5); // CXXFunctionalCastExpr 69*f4a2713aSLionel Sambuc A = int(); // CXXZeroInitValueExpr 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc Base *b = new Base(4); // CXXNewExpr 72*f4a2713aSLionel Sambuc delete b; // CXXDeleteExpr 73*f4a2713aSLionel Sambuc } 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc // FIXME: The comment on CXXTemporaryObjectExpr is broken, this doesn't make 77*f4a2713aSLionel Sambuc // one. 78*f4a2713aSLionel Sambuc struct CtorStruct { CtorStruct(int, float); }; 79*f4a2713aSLionel Sambuc create_CtorStruct()80*f4a2713aSLionel SambucCtorStruct create_CtorStruct() { 81*f4a2713aSLionel Sambuc return CtorStruct(1, 3.14f); // CXXTemporaryObjectExpr 82*f4a2713aSLionel Sambuc }; 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc // CharacterLiteral variants 85*f4a2713aSLionel Sambuc const char char_value = 'a'; 86*f4a2713aSLionel Sambuc const wchar_t wchar_t_value = L'ı'; 87*f4a2713aSLionel Sambuc const char16_t char16_t_value = u'ç'; 88*f4a2713aSLionel Sambuc const char32_t char32_t_value = U'∂'; 89