From f774dca9123e16ca22504f6dc856292b8d4a621f Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 27 Feb 2016 19:31:02 +0100 Subject: [PATCH] Cleaning up static asserts for .where(true) --- include/sqlpp11/where.h | 24 ++++++++---------------- test_static_asserts/where.cpp | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index fac903dd..ae570602 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -217,9 +217,9 @@ namespace sqlpp SQLPP_PORTABLE_STATIC_ASSERT(assert_where_t, "calling where() or uncontionally() required"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_where_expressions_t, - "at least one argument is not a boolean expression in where()"); - SQLPP_PORTABLE_STATIC_ASSERT(assert_where_boolean_t, "at least one argument is not a boolean expression in where()"); + SQLPP_PORTABLE_STATIC_ASSERT(assert_where_boolean_expression_t, + "at least one argument is not a sqlpp::boolean expression in where(). Please use " + ".unconditionally() instead of .where(true), or sqlpp::value(bool)"); SQLPP_PORTABLE_STATIC_ASSERT(assert_where_no_aggregate_functions_t, "at least one aggregate function used in where()"); SQLPP_PORTABLE_STATIC_ASSERT(assert_where_static_count_args_t, "missing argument in where()"); @@ -230,8 +230,9 @@ namespace sqlpp // https://connect.microsoft.com/VisualStudio/feedback/details/2173198 // template // using check_where_t = static_combined_check_t< - // static_check_t::value...>::value, assert_where_expressions_t>, - // static_check_t::value...>::value, assert_where_boolean_t>, + // static_check_t::value...>::value, + // assert_where_boolean_expressions_t>, + // static_check_t::value...>::value, assert_where_boolean_expression_t>, // static_check_t::value)...>::value, // assert_where_no_aggregate_functions_t>>; template @@ -239,8 +240,8 @@ namespace sqlpp { using type = static_combined_check_t< static_check_t::type::value...>::value, - assert_where_expressions_t>, - static_check_t::value...>::value, assert_where_boolean_t>, + assert_where_boolean_expression_t>, + static_check_t::value...>::value, assert_where_boolean_expression_t>, static_check_t::type::value)...>::value, assert_where_no_aggregate_functions_t>>; }; @@ -328,15 +329,6 @@ namespace sqlpp assert_where_t, consistent_t>::type; - template - auto where(bool) const -> bad_statement - { - static_assert(wrong_t::value, - ".where(bool) is not allowed any more. Please use unconditionally() to replace " - ".where(true). Use sqlpp::value(bool) if you really want to use a bool here"); - return {}; - } - auto unconditionally() const -> _new_statement_t> { return {static_cast&>(*this), where_data_t{}}; diff --git a/test_static_asserts/where.cpp b/test_static_asserts/where.cpp index 4783ceb7..8f838716 100644 --- a/test_static_asserts/where.cpp +++ b/test_static_asserts/where.cpp @@ -84,17 +84,17 @@ namespace where_static_check(); // Try assignment as condition - where_static_check(t.gamma = true); + where_static_check(t.gamma = true); // Try non-boolean expression - where_static_check(t.alpha); + where_static_check(t.alpha); // Try some other types as expressions - where_static_check("true"); - where_static_check(17); - where_static_check('c'); - where_static_check(nullptr); - where_static_check(t.alpha.as(t.beta)); + where_static_check("true"); + where_static_check(17); + where_static_check('c'); + where_static_check(nullptr); + where_static_check(t.alpha.as(t.beta)); // Try using aggregate functions in where where_static_check(count(t.alpha) > 0); @@ -111,17 +111,17 @@ namespace where_dynamic_check(t.gamma == true); // Try assignment as condition - where_dynamic_check(t.gamma = true); + where_dynamic_check(t.gamma = true); // Try non-boolean expression - where_dynamic_check(t.alpha); + where_dynamic_check(t.alpha); // Try some other types as expressions - where_dynamic_check("true"); - where_dynamic_check(17); - where_dynamic_check('c'); - where_dynamic_check(nullptr); - where_dynamic_check(t.alpha.as(t.beta)); + where_dynamic_check("true"); + where_dynamic_check(17); + where_dynamic_check('c'); + where_dynamic_check(nullptr); + where_dynamic_check(t.alpha.as(t.beta)); // Try using aggregate functions in where where_dynamic_check(count(t.alpha) > 0);