1 // { dg-do "run" } 2 #include <cassert> 3 4 struct A 5 { 6 double a; 7 double b; 8 }; 9 10 struct B 11 { 12 A a; 13 }; 14 15 struct C 16 : public A { }; 17 18 struct D 19 { DD20 D(const D&) throw() { } 21 }; 22 23 struct E 24 { EE25 E(const E&) throw(int) { } 26 }; 27 28 struct E1 29 { E1E130 E1(const E1&) throw(int) { throw int(); } 31 }; 32 33 struct F 34 { FF35 F() throw() { } 36 }; 37 38 struct G 39 { GG40 G() throw(int) { throw int(); } 41 }; 42 43 struct H 44 { HH45 H(H&) throw(int) { } 46 }; 47 48 struct H1 49 { H1H150 H1(H1&) throw(int) { throw int(); } 51 }; 52 53 struct I 54 { II55 I(I&) throw(int) { } II56 I(const I&) throw() { } 57 }; 58 59 struct I1 60 { I1I161 I1(I1&) throw(int) { throw int(); } I1I162 I1(const I1&) throw() { } 63 }; 64 65 struct J 66 { JJ67 J(J&) throw() { } JJ68 J(const J&) throw() { } JJ69 J(volatile J&) throw() { } JJ70 J(const volatile J&) throw() { } 71 }; 72 73 template<typename T> 74 bool f()75 f() 76 { return __has_nothrow_copy(T); } 77 78 template<typename T> 79 class My 80 { 81 public: 82 bool f()83 f() 84 { return !!__has_nothrow_copy(T); } 85 }; 86 87 template<typename T> 88 class My2 89 { 90 public: 91 static const bool trait = __has_nothrow_copy(T); 92 }; 93 94 template<typename T> 95 const bool My2<T>::trait; 96 97 template<typename T, bool b = __has_nothrow_copy(T)> 98 struct My3_help 99 { static const bool trait = b; }; 100 101 template<typename T, bool b> 102 const bool My3_help<T, b>::trait; 103 104 template<typename T> 105 class My3 106 { 107 public: 108 bool f()109 f() 110 { return My3_help<T>::trait; } 111 }; 112 113 #define PTEST(T) (__has_nothrow_copy(T) && f<T>() \ 114 && My<T>().f() && My2<T>::trait && My3<T>().f()) 115 116 #define NTEST(T) (!__has_nothrow_copy(T) && !f<T>() \ 117 && !My<T>().f() && !My2<T>::trait && !My3<T>().f()) 118 main()119int main() 120 { 121 assert (PTEST (int)); 122 assert (NTEST (int (int))); 123 assert (NTEST (void)); 124 assert (PTEST (A)); 125 assert (PTEST (B)); 126 assert (PTEST (C)); 127 assert (NTEST (C[])); 128 assert (PTEST (D)); 129 assert (NTEST (E)); 130 assert (NTEST (E1)); 131 assert (PTEST (F)); 132 assert (PTEST (G)); 133 assert (NTEST (H)); 134 assert (NTEST (H1)); 135 assert (NTEST (I)); 136 assert (NTEST (I1)); 137 assert (PTEST (J)); 138 139 return 0; 140 } 141