From 5aaca8667cbbfa2ae5b72d778796daa3375b46c0 Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Fri, 17 Nov 2023 18:19:05 +0200 Subject: [PATCH] Fixed constexpr lambda only being available with C++17 --- dev/functional/config.h | 6 ++++++ dev/functional/cxx_core_features.h | 4 ++++ dev/udf_proxy.h | 2 +- include/sqlite_orm/sqlite_orm.h | 12 +++++++++++- tests/user_defined_functions.cpp | 4 ++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dev/functional/config.h b/dev/functional/config.h index ec984c51d..2c88944ca 100644 --- a/dev/functional/config.h +++ b/dev/functional/config.h @@ -6,6 +6,12 @@ #include #endif +#ifdef SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED +#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 constexpr +#else +#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 +#endif + #ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED #define SQLITE_ORM_INLINE_VAR inline #else diff --git a/dev/functional/cxx_core_features.h b/dev/functional/cxx_core_features.h index d71644fd3..ee804439a 100644 --- a/dev/functional/cxx_core_features.h +++ b/dev/functional/cxx_core_features.h @@ -37,6 +37,10 @@ #define SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED #endif +#if __cpp_constexpr >= 201603L +#define SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED +#endif + #if __cpp_if_constexpr >= 201606L #define SQLITE_ORM_IF_CONSTEXPR_SUPPORTED #endif diff --git a/dev/udf_proxy.h b/dev/udf_proxy.h index b84431087..7b81d1c2a 100644 --- a/dev/udf_proxy.h +++ b/dev/udf_proxy.h @@ -57,7 +57,7 @@ namespace sqlite_orm { std::allocator allocator; using traits = std::allocator_traits; - constexpr auto deallocate = [](void* location) noexcept { + SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept { std::allocator allocator; using traits = std::allocator_traits; traits::deallocate(allocator, (UDF*)location, 1); diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 213aaa13a..e13bbe52c 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -65,6 +65,10 @@ using std::nullptr_t; #define SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED #endif +#if __cpp_constexpr >= 201603L +#define SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED +#endif + #if __cpp_if_constexpr >= 201606L #define SQLITE_ORM_IF_CONSTEXPR_SUPPORTED #endif @@ -167,6 +171,12 @@ using std::nullptr_t; #include #endif +#ifdef SQLITE_ORM_CONSTEXPR_LAMBDAS_SUPPORTED +#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 constexpr +#else +#define SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 +#endif + #ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED #define SQLITE_ORM_INLINE_VAR inline #else @@ -14885,7 +14895,7 @@ namespace sqlite_orm { std::allocator allocator; using traits = std::allocator_traits; - constexpr auto deallocate = [](void* location) noexcept { + SQLITE_ORM_CONSTEXPR_LAMBDA_CPP17 auto deallocate = [](void* location) noexcept { std::allocator allocator; using traits = std::allocator_traits; traits::deallocate(allocator, (UDF*)location, 1); diff --git a/tests/user_defined_functions.cpp b/tests/user_defined_functions.cpp index 0c67031ff..0ac76a3f4 100644 --- a/tests/user_defined_functions.cpp +++ b/tests/user_defined_functions.cpp @@ -171,7 +171,7 @@ int FirstFunction::objectsCount = 0; int FirstFunction::callsCount = 0; #if __cpp_aligned_new >= 201606L -struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) OverAlignedScalarFunction { +struct alignas(2 * __STDCPP_DEFAULT_NEW_ALIGNMENT__) OverAlignedScalarFunction { int operator()(int arg) const { return arg; } @@ -181,7 +181,7 @@ struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) OverAlignedScalarFunction { } }; -struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2) OverAlignedAggregateFunction { +struct alignas(2 * __STDCPP_DEFAULT_NEW_ALIGNMENT__) OverAlignedAggregateFunction { double sum = 0; void step(double arg) {