|
126 | 126 | # endif |
127 | 127 | #endif |
128 | 128 |
|
| 129 | +# if defined( __cpp_deleted_function_with_reason ) |
| 130 | +# define CATCH_INTERNAL_DELETE( x ) delete (x) |
| 131 | +#else |
| 132 | +# define CATCH_INTERNAL_DELETE( x ) delete |
| 133 | +#endif |
| 134 | + |
129 | 135 | namespace Catch { |
130 | 136 |
|
131 | 137 | namespace Detail { |
@@ -160,9 +166,6 @@ namespace Catch { |
160 | 166 | struct capture_by_value<std::partial_ordering> : std::true_type {}; |
161 | 167 | #endif |
162 | 168 |
|
163 | | - template <typename T> |
164 | | - struct always_false : std::false_type {}; |
165 | | - |
166 | 169 | class ITransientExpression { |
167 | 170 | bool m_isBinaryExpression; |
168 | 171 | bool m_result; |
@@ -211,61 +214,38 @@ namespace Catch { |
211 | 214 | m_rhs( rhs ) |
212 | 215 | {} |
213 | 216 |
|
| 217 | + |
214 | 218 | template<typename T> |
215 | | - auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
216 | | - static_assert(always_false<T>::value, |
217 | | - "chained comparisons are not supported inside assertions, " |
218 | | - "wrap the expression inside parentheses, or decompose it"); |
219 | | - } |
| 219 | + auto operator&&( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 220 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
220 | 221 |
|
221 | 222 | template<typename T> |
222 | | - auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
223 | | - static_assert(always_false<T>::value, |
224 | | - "chained comparisons are not supported inside assertions, " |
225 | | - "wrap the expression inside parentheses, or decompose it"); |
226 | | - } |
| 223 | + auto operator||( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 224 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
227 | 225 |
|
228 | 226 | template<typename T> |
229 | | - auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
230 | | - static_assert(always_false<T>::value, |
231 | | - "chained comparisons are not supported inside assertions, " |
232 | | - "wrap the expression inside parentheses, or decompose it"); |
233 | | - } |
| 227 | + auto operator==( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 228 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
234 | 229 |
|
235 | 230 | template<typename T> |
236 | | - auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
237 | | - static_assert(always_false<T>::value, |
238 | | - "chained comparisons are not supported inside assertions, " |
239 | | - "wrap the expression inside parentheses, or decompose it"); |
240 | | - } |
| 231 | + auto operator!=( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 232 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
241 | 233 |
|
242 | 234 | template<typename T> |
243 | | - auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
244 | | - static_assert(always_false<T>::value, |
245 | | - "chained comparisons are not supported inside assertions, " |
246 | | - "wrap the expression inside parentheses, or decompose it"); |
247 | | - } |
| 235 | + auto operator>( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 236 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
248 | 237 |
|
249 | 238 | template<typename T> |
250 | | - auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
251 | | - static_assert(always_false<T>::value, |
252 | | - "chained comparisons are not supported inside assertions, " |
253 | | - "wrap the expression inside parentheses, or decompose it"); |
254 | | - } |
| 239 | + auto operator<( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 240 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
255 | 241 |
|
256 | 242 | template<typename T> |
257 | | - auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
258 | | - static_assert(always_false<T>::value, |
259 | | - "chained comparisons are not supported inside assertions, " |
260 | | - "wrap the expression inside parentheses, or decompose it"); |
261 | | - } |
| 243 | + auto operator>=( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 244 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
262 | 245 |
|
263 | 246 | template<typename T> |
264 | | - auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { |
265 | | - static_assert(always_false<T>::value, |
266 | | - "chained comparisons are not supported inside assertions, " |
267 | | - "wrap the expression inside parentheses, or decompose it"); |
268 | | - } |
| 247 | + auto operator<=( T ) const -> BinaryExpr<LhsT, RhsT const&> const = |
| 248 | + CATCH_INTERNAL_DELETE( "chained comparisons are not supported" ); |
269 | 249 | }; |
270 | 250 |
|
271 | 251 | template<typename LhsT> |
@@ -419,19 +399,16 @@ namespace Catch { |
419 | 399 |
|
420 | 400 | #undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR |
421 | 401 |
|
| 402 | + |
422 | 403 | template<typename RhsT> |
423 | | - friend auto operator && ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> { |
424 | | - static_assert(always_false<RhsT>::value, |
425 | | - "operator&& is not supported inside assertions, " |
426 | | - "wrap the expression inside parentheses, or decompose it"); |
427 | | - } |
| 404 | + friend auto operator&&( ExprLhs&&, RhsT&& ) |
| 405 | + -> BinaryExpr<LhsT, RhsT const&> = CATCH_INTERNAL_DELETE( |
| 406 | + "'&&' is not supported inside assertions" ); |
428 | 407 |
|
429 | 408 | template<typename RhsT> |
430 | | - friend auto operator || ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> { |
431 | | - static_assert(always_false<RhsT>::value, |
432 | | - "operator|| is not supported inside assertions, " |
433 | | - "wrap the expression inside parentheses, or decompose it"); |
434 | | - } |
| 409 | + friend auto operator||( ExprLhs&&, RhsT&& ) |
| 410 | + -> BinaryExpr<LhsT, RhsT const&> = CATCH_INTERNAL_DELETE( |
| 411 | + "'||' is not supported inside assertions" ); |
435 | 412 |
|
436 | 413 | constexpr auto makeUnaryExpr() const -> UnaryExpr<LhsT> { |
437 | 414 | return UnaryExpr<LhsT>{ m_lhs }; |
|
0 commit comments