OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [template/] [sfinae13.C] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// DR 339
2
//
3
// Test of the use of casts with SFINAE
4
 
5
// Boilerplate helpers
6
typedef char yes_type;
7
struct no_type { char data[2]; };
8
 
9
template T create_a();
10
template struct type { };
11
 
12
template struct enable_if { typedef T type; };
13
template struct enable_if { };
14
 
15
#define JOIN( X, Y ) DO_JOIN( X, Y )
16
#define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
17
#define DO_JOIN2( X, Y ) X##Y
18
 
19
#define CHECK_CAST(CastKind)                                            \
20
template                                        \
21
 typename enable_if<(sizeof((JOIN(CastKind,_cast)(create_a())), 0) > 0), \
22
                   yes_type>::type                                      \
23
  JOIN(check_,JOIN(CastKind,_cast))(int);                               \
24
                                                                        \
25
template                                        \
26
  no_type JOIN(check_,JOIN(CastKind,_cast))(...);                       \
27
                                                                        \
28
template                                        \
29
struct JOIN(has_,JOIN(CastKind,_cast))                                  \
30
{                                                                       \
31
  static const bool value =                                             \
32
    (sizeof(JOIN(check_,JOIN(CastKind,_cast))(0)) == sizeof(yes_type)); \
33
}
34
 
35
template
36
typename enable_if<(sizeof(((U)create_a()), 0) > 0), yes_type>::type
37
  check_c_cast(int);
38
 
39
template no_type check_c_cast(...);
40
 
41
template
42
struct has_c_cast
43
{
44
  static const bool value =
45
    (sizeof(check_c_cast(0)) == sizeof(yes_type));
46
};
47
 
48
#ifdef __GXX_EXPERIMENTAL_CXX0X__
49
#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
50
#else
51
#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
52
#endif
53
 
54
CHECK_CAST(static);
55
CHECK_CAST(dynamic);
56
CHECK_CAST(const);
57
CHECK_CAST(reinterpret);
58
 
59
struct X { virtual void f(); };
60
struct Y { operator bool(); };
61
struct Z : public X { };
62
 
63
STATIC_ASSERT((has_static_cast::value));
64
STATIC_ASSERT((!has_static_cast::value));
65
STATIC_ASSERT((has_static_cast::value));
66
 
67
STATIC_ASSERT(!(has_dynamic_cast::value));
68
STATIC_ASSERT(!(has_dynamic_cast::value));
69
STATIC_ASSERT(!(has_dynamic_cast::value));
70
STATIC_ASSERT(!(has_dynamic_cast::value));
71
STATIC_ASSERT((has_dynamic_cast::value));
72
STATIC_ASSERT((has_dynamic_cast::value));
73
STATIC_ASSERT(!(has_dynamic_cast::value));
74
 
75
STATIC_ASSERT(!(has_const_cast::value));
76
STATIC_ASSERT((has_const_cast::value));
77
STATIC_ASSERT((has_const_cast::value));
78
STATIC_ASSERT(!(has_const_cast::value));
79
 
80
STATIC_ASSERT((has_reinterpret_cast::value));
81
STATIC_ASSERT(!(has_reinterpret_cast::value));
82
STATIC_ASSERT(!(has_reinterpret_cast::value));
83
 
84
STATIC_ASSERT((has_c_cast::value));
85
STATIC_ASSERT(!(has_c_cast::value));
86
STATIC_ASSERT(!(has_c_cast::value));

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.