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