Mercurial > hg > CbC > CbC_llvm
comparison libcxxabi/test/test_aux_runtime.pass.cpp @ 207:2e18cbf3894f
LLVM12
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Jun 2021 06:07:14 +0900 |
parents | 0572611fdcc8 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
173:0572611fdcc8 | 207:2e18cbf3894f |
---|---|
7 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
8 | 8 |
9 // UNSUPPORTED: no-exceptions | 9 // UNSUPPORTED: no-exceptions |
10 | 10 |
11 #include <typeinfo> | 11 #include <typeinfo> |
12 #include <iostream> | |
13 | 12 |
14 // Test taken from 5.2.8.2 | 13 // Test taken from 5.2.8.2 |
15 // When typeid is applied to a glvalue expression whose type is a polymorphic | 14 // When typeid is applied to a glvalue expression whose type is a polymorphic |
16 // class type, (10.3), the result refers to a std::type_info object | 15 // class type, (10.3), the result refers to a std::type_info object |
17 // representing the type of the most derived object (1.8) (that is, the | 16 // representing the type of the most derived object (1.8) (that is, the |
28 | 27 |
29 B *bp = NULL; | 28 B *bp = NULL; |
30 try {bool b = typeid(*bp) == typeid (A); ((void)b); } | 29 try {bool b = typeid(*bp) == typeid (A); ((void)b); } |
31 catch ( const std::bad_typeid &) { return true; } | 30 catch ( const std::bad_typeid &) { return true; } |
32 return false; | 31 return false; |
33 } | 32 } |
34 | 33 |
35 | 34 |
36 // The value of a failed cast to pointer type is the null pointer value of | 35 // The value of a failed cast to pointer type is the null pointer value of |
37 // the required result type. A failed cast to reference type throws | 36 // the required result type. A failed cast to reference type throws |
38 // std::bad_cast (18.7.2). | 37 // std::bad_cast (18.7.2). |
44 D d; | 43 D d; |
45 B *bp = (B*)&d; // cast needed to break protection | 44 B *bp = (B*)&d; // cast needed to break protection |
46 try { D &dr = dynamic_cast<D&> (*bp); ((void)dr); } | 45 try { D &dr = dynamic_cast<D&> (*bp); ((void)dr); } |
47 catch ( const std::bad_cast & ) { return true; } | 46 catch ( const std::bad_cast & ) { return true; } |
48 return false; | 47 return false; |
49 } | 48 } |
50 | 49 |
51 int main ( ) { | 50 int main ( ) { |
52 int ret_val = 0; | 51 int ret_val = 0; |
53 | 52 |
54 if ( !bad_typeid_test ()) { | 53 if ( !bad_typeid_test ()) { |
55 std::cerr << "TypeID test failed!" << std::endl; | |
56 ret_val = 1; | 54 ret_val = 1; |
57 } | 55 } |
58 | 56 |
59 if ( !bad_cast_test ()) { | 57 if ( !bad_cast_test ()) { |
60 std::cerr << "Bad cast test failed!" << std::endl; | 58 ret_val = 2; |
61 ret_val = 1; | |
62 } | 59 } |
63 | 60 |
64 return ret_val; | 61 return ret_val; |
65 } | 62 } |