Skip to content

Commit 0cac51f

Browse files
committed
WIP: Use =delete instead of static_assert(always_false)
1 parent 11a96e1 commit 0cac51f

1 file changed

Lines changed: 30 additions & 53 deletions

File tree

src/catch2/internal/catch_decomposer.hpp

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@
126126
# endif
127127
#endif
128128

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+
129135
namespace Catch {
130136

131137
namespace Detail {
@@ -160,9 +166,6 @@ namespace Catch {
160166
struct capture_by_value<std::partial_ordering> : std::true_type {};
161167
#endif
162168

163-
template <typename T>
164-
struct always_false : std::false_type {};
165-
166169
class ITransientExpression {
167170
bool m_isBinaryExpression;
168171
bool m_result;
@@ -211,61 +214,38 @@ namespace Catch {
211214
m_rhs( rhs )
212215
{}
213216

217+
214218
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" );
220221

221222
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" );
227225

228226
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" );
234229

235230
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" );
241233

242234
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" );
248237

249238
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" );
255241

256242
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" );
262245

263246
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" );
269249
};
270250

271251
template<typename LhsT>
@@ -419,19 +399,16 @@ namespace Catch {
419399

420400
#undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR
421401

402+
422403
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" );
428407

429408
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" );
435412

436413
constexpr auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
437414
return UnaryExpr<LhsT>{ m_lhs };

0 commit comments

Comments
 (0)