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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [template/] [sfinae10.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 various unary operators 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 DEFINE_PREFIX_UNARY_TRAIT(Name,Op)                      \
20
template                                            \
21
  typename enable_if<(sizeof(Op create_a(), 1) > 0),         \
22
                     yes_type>::type                            \
23
  JOIN(check_,Name)(int);                                       \
24
                                                                \
25
template                                            \
26
  no_type JOIN(check_,Name)(...);                               \
27
                                                                \
28
template                                            \
29
struct Name                                                     \
30
{                                                               \
31
  static const bool value =                                     \
32
    (sizeof(JOIN(check_,Name)(0)) == sizeof(yes_type));     \
33
}
34
 
35
#define DEFINE_POSTFIX_UNARY_TRAIT(Name,Op)                     \
36
template                                            \
37
  typename enable_if<(sizeof(create_a() Op, 1) > 0),         \
38
                     yes_type>::type                            \
39
  JOIN(check_,Name)(int);                                       \
40
                                                                \
41
template                                            \
42
  no_type JOIN(check_,Name)(...);                               \
43
                                                                \
44
template                                            \
45
struct Name                                                     \
46
{                                                               \
47
  static const bool value =                                     \
48
    (sizeof(JOIN(check_,Name)(0)) == sizeof(yes_type));     \
49
}
50
 
51
#ifdef __GXX_EXPERIMENTAL_CXX0X__
52
#  define STATIC_ASSERT(Expr) static_assert(Expr, #Expr)
53
#else
54
#  define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1]
55
#endif
56
 
57
struct W {
58
  W operator+();
59
  W operator-();
60
  int operator*();
61
  W operator~();
62
  bool operator!();
63
  W& operator++();
64
  W& operator--();
65
  W& operator++(int);
66
  W& operator--(int);
67
};
68
 
69
struct X { };
70
X operator+(X);
71
X operator-(X);
72
int operator*(X);
73
X operator~(X);
74
bool operator!(X);
75
X& operator++(X&);
76
X& operator--(X&);
77
X& operator++(X&, int);
78
X& operator--(X&, int);
79
 
80
struct Y { };
81
 
82
struct Z {
83
private:
84
  Z operator+(); // { dg-error "is private" }
85
  Z operator-(); // { dg-error "is private" }
86
  int operator*(); // { dg-error "is private" }
87
  Z operator~(); // { dg-error "is private" }
88
  bool operator!(); // { dg-error "is private" }
89
  Z& operator++(); // { dg-error "is private" }
90
  Z& operator--(); // { dg-error "is private" }
91
  Z& operator++(int); // { dg-error "is private" }
92
  Z& operator--(int); // { dg-error "is private" }
93
};
94
 
95
// has_unary_plus
96
DEFINE_PREFIX_UNARY_TRAIT(has_unary_plus, +); // { dg-error "within this context" }
97
STATIC_ASSERT((has_unary_plus::value));
98
STATIC_ASSERT((!has_unary_plus::value));
99
STATIC_ASSERT((has_unary_plus::value));
100
STATIC_ASSERT((has_unary_plus::value));
101
STATIC_ASSERT((!has_unary_plus::value));
102
 
103
// is_negatable
104
DEFINE_PREFIX_UNARY_TRAIT(is_negatable, -); // { dg-error "within this context" }
105
STATIC_ASSERT((is_negatable::value));
106
STATIC_ASSERT((!is_negatable::value));
107
STATIC_ASSERT((is_negatable::value));
108
STATIC_ASSERT((is_negatable::value));
109
STATIC_ASSERT((!is_negatable::value));
110
 
111
// is_dereferenceable
112
DEFINE_PREFIX_UNARY_TRAIT(is_dereferenceable, *); // { dg-error "within this context" }
113
STATIC_ASSERT((!is_dereferenceable::value));
114
STATIC_ASSERT((is_dereferenceable::value));
115
STATIC_ASSERT((is_dereferenceable::value));
116
STATIC_ASSERT((is_dereferenceable::value));
117
STATIC_ASSERT((!is_dereferenceable::value));
118
 
119
// has_bitwise_not
120
DEFINE_PREFIX_UNARY_TRAIT(has_bitwise_not, ~); // { dg-error "within this context" }
121
STATIC_ASSERT((has_bitwise_not::value));
122
STATIC_ASSERT((!has_bitwise_not::value));
123
STATIC_ASSERT((has_bitwise_not::value));
124
STATIC_ASSERT((has_bitwise_not::value));
125
STATIC_ASSERT((!has_bitwise_not::value));
126
 
127
// has_truth_not
128
DEFINE_PREFIX_UNARY_TRAIT(has_truth_not, !); // { dg-error "within this context" }
129
STATIC_ASSERT((has_truth_not::value));
130
STATIC_ASSERT((has_truth_not::value));
131
STATIC_ASSERT((has_truth_not::value));
132
STATIC_ASSERT((has_truth_not::value));
133
STATIC_ASSERT((!has_truth_not::value));
134
 
135
// has_preincrement
136
DEFINE_PREFIX_UNARY_TRAIT(has_preincrement, ++); // { dg-error "within this context" }
137
STATIC_ASSERT((has_preincrement::value));
138
STATIC_ASSERT((has_preincrement::value));
139
STATIC_ASSERT((!has_preincrement::value));
140
STATIC_ASSERT((has_preincrement::value));
141
STATIC_ASSERT((has_preincrement::value));
142
STATIC_ASSERT((!has_preincrement::value));
143
 
144
// has_predecrement
145
DEFINE_PREFIX_UNARY_TRAIT(has_predecrement, --); // { dg-error "within this context" }
146
STATIC_ASSERT((has_predecrement::value));
147
STATIC_ASSERT((has_predecrement::value));
148
STATIC_ASSERT((!has_predecrement::value));
149
STATIC_ASSERT((has_predecrement::value));
150
STATIC_ASSERT((has_predecrement::value));
151
STATIC_ASSERT((!has_predecrement::value));
152
 
153
// has_postincrement
154
DEFINE_POSTFIX_UNARY_TRAIT(has_postincrement, ++); // { dg-error "within this context" }
155
STATIC_ASSERT((has_postincrement::value));
156
STATIC_ASSERT((has_postincrement::value));
157
STATIC_ASSERT((!has_postincrement::value));
158
STATIC_ASSERT((has_postincrement::value));
159
STATIC_ASSERT((has_postincrement::value));
160
STATIC_ASSERT((!has_postincrement::value));
161
 
162
// has_postdecrement
163
DEFINE_POSTFIX_UNARY_TRAIT(has_postdecrement, --); // { dg-error "within this context" }
164
STATIC_ASSERT((has_postdecrement::value));
165
STATIC_ASSERT((has_postdecrement::value));
166
STATIC_ASSERT((!has_postdecrement::value));
167
STATIC_ASSERT((has_postdecrement::value));
168
STATIC_ASSERT((has_postdecrement::value));
169
STATIC_ASSERT((!has_postdecrement::value));
170
 
171
// Check for private members
172
STATIC_ASSERT((has_unary_plus::value)); // { dg-message "required from here" }
173
STATIC_ASSERT((is_negatable::value)); // { dg-message "required from here" }
174
STATIC_ASSERT((is_dereferenceable::value)); // { dg-message "required from here" }
175
STATIC_ASSERT((has_bitwise_not::value)); // { dg-message "required from here" }
176
STATIC_ASSERT((has_truth_not::value)); // { dg-message "required from here" }
177
STATIC_ASSERT((has_preincrement::value)); // { dg-message "required from here" }
178
STATIC_ASSERT((has_predecrement::value)); // { dg-message "required from here" }
179
STATIC_ASSERT((has_postincrement::value)); // { dg-message "required from here" }
180
STATIC_ASSERT((has_postdecrement::value)); // { dg-message "required from here" }
181
 

powered by: WebSVN 2.1.0

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