| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 3 |
#include <cassert> |
| 4 |
#include <exception> |
| 5 |
|
| 6 |
struct A |
| 7 |
{ |
| 8 |
double a; |
| 9 |
double b; |
| 10 |
}; |
| 11 |
|
| 12 |
class B |
| 13 |
{ |
| 14 |
virtual void rotate(int) { } |
| 15 |
}; |
| 16 |
|
| 17 |
class C |
| 18 |
: public B { }; |
| 19 |
|
| 20 |
union U |
| 21 |
{ |
| 22 |
double a; |
| 23 |
double b; |
| 24 |
}; |
| 25 |
|
| 26 |
template<typename T> |
| 27 |
bool |
| 28 |
f() |
| 29 |
{ return __is_polymorphic(T); } |
| 30 |
|
| 31 |
template<typename T> |
| 32 |
class My |
| 33 |
{ |
| 34 |
public: |
| 35 |
bool |
| 36 |
f() |
| 37 |
{ return !!__is_polymorphic(T); } |
| 38 |
}; |
| 39 |
|
| 40 |
template<typename T> |
| 41 |
class My2 |
| 42 |
{ |
| 43 |
public: |
| 44 |
static const bool trait = __is_polymorphic(T); |
| 45 |
}; |
| 46 |
|
| 47 |
template<typename T> |
| 48 |
const bool My2<T>::trait; |
| 49 |
|
| 50 |
template<typename T, bool b = __is_polymorphic(T)> |
| 51 |
struct My3_help |
| 52 |
{ static const bool trait = b; }; |
| 53 |
|
| 54 |
template<typename T, bool b> |
| 55 |
const bool My3_help<T, b>::trait; |
| 56 |
|
| 57 |
template<typename T> |
| 58 |
class My3 |
| 59 |
{ |
| 60 |
public: |
| 61 |
bool |
| 62 |
f() |
| 63 |
{ return My3_help<T>::trait; } |
| 64 |
}; |
| 65 |
|
| 66 |
#define PTEST(T) (__is_polymorphic(T) && f<T>() \ |
| 67 |
&& My<T>().f() && My2<T>::trait && My3<T>().f()) |
| 68 |
|
| 69 |
#define NTEST(T) (!__is_polymorphic(T) && !f<T>() \ |
| 70 |
&& !My<T>().f() && !My2<T>::trait && !My3<T>().f()) |
| 71 |
|
| 72 |
int main() |
| 73 |
{ |
| 74 |
assert (NTEST (int)); |
| 75 |
assert (NTEST (void)); |
| 76 |
assert (PTEST (std::exception)); |
| 77 |
assert (NTEST (A)); |
| 78 |
assert (PTEST (B)); |
| 79 |
assert (PTEST (C)); |
| 80 |
assert (NTEST (C[])); |
| 81 |
assert (NTEST (U)); |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |