| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-additional-options "-Wno-return-type" } */ |
| 3 |
|
| 4 |
typedef __SIZE_TYPE__ size_t; |
| 5 |
extern "C" void *memcpy (void *, __const void *, size_t); |
| 6 |
template < class Dest, class Source > struct BitCastHelper { |
| 7 |
static Dest cast (const Source & source) __attribute__ ((always_inline)) { |
| 8 |
Dest dest; |
| 9 |
memcpy (0, &source, sizeof dest); |
| 10 |
} |
| 11 |
}; |
| 12 |
template < class Dest, class Source > Dest BitCast (Source) |
| 13 |
{ |
| 14 |
BitCastHelper < Dest, Source >::cast (0); |
| 15 |
} |
| 16 |
|
| 17 |
class MaybeObject |
| 18 |
{ |
| 19 |
}; |
| 20 |
class Object:MaybeObject |
| 21 |
{ |
| 22 |
public: |
| 23 |
static Object *cast (Object *) { |
| 24 |
} |
| 25 |
}; |
| 26 |
class HeapObject:public Object |
| 27 |
{ |
| 28 |
}; |
| 29 |
class String:public HeapObject |
| 30 |
{ |
| 31 |
}; |
| 32 |
class ExternalString:public String |
| 33 |
{ |
| 34 |
}; |
| 35 |
class ExternalTwoByteString:public ExternalString |
| 36 |
{ |
| 37 |
}; |
| 38 |
|
| 39 |
template < typename T > class Handle |
| 40 |
{ |
| 41 |
public: |
| 42 |
Handle () { |
| 43 |
} |
| 44 |
T *operator* () const; |
| 45 |
template < class S > static Handle < T > cast (Handle < S > that) { |
| 46 |
T::cast (*that); |
| 47 |
} |
| 48 |
T **location_; |
| 49 |
}; |
| 50 |
|
| 51 |
template < typename T > T * Handle < T >::operator* () const |
| 52 |
{ |
| 53 |
*BitCast < T ** >(location_); |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
TestCharacterStream () |
| 58 |
{ |
| 59 |
Handle < String > uc16_string; |
| 60 |
Handle < ExternalTwoByteString >::cast (uc16_string); |
| 61 |
} |