From 87838c82cf6848cf5dc4bc95a82c7b127c4a9d83 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 28 Feb 2019 20:01:17 +0100 Subject: compat/macros: move more macros to macros1 Actually `macros.hpp' should become a util header. --- compat/macros.hpp | 21 --------------------- compat/macros1.h | 6 ++++++ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/compat/macros.hpp b/compat/macros.hpp index 08be9b4a..497933cf 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -2,10 +2,6 @@ #include "macros1.h" -#ifdef __cplusplus - -// from now only C++ - #include #include @@ -23,24 +19,7 @@ using remove_cvref_t = typename cxx20_compat::remove_cvref::type; template using to_const_ref_t = std::add_lvalue_reference_t>>; -// causes ICE in Visual Studio 2017 Preview. the ICE was reported and they handle them seriously in due time. -// the ICE is caused by decltype(auto) and const& return value -//#define eval_once(expr) ([&]() -> decltype(auto) { static decltype(auto) ret___1132 = (expr); return (decltype(ret___1132) const&) ret___1132; }()) - -#define eval_once(expr) eval_once2(expr, __COUNTER__) - -#define eval_once2(expr, ctr) \ - ([&] { \ - [[maybe_unused]] \ - static auto PP_CAT(init, ctr) = (((void)(expr)), 0); \ - }()) - template using cv_qualified = std::conditional_t>, remove_cvref_t, to_const_ref_t>; - -#define progn(...) ([&]() -> decltype(auto) { __VA_ARGS__ }()) - -// end c++-only macros -#endif diff --git a/compat/macros1.h b/compat/macros1.h index b1137e63..5e3129d5 100644 --- a/compat/macros1.h +++ b/compat/macros1.h @@ -39,3 +39,9 @@ #else # define unreachable() do { __builtin_unreachable(); *(volatile int*)nullptr = 0; } while (0) /* NOLINT(clang-analyzer-core.NullDereference) */ #endif + +#ifdef __cplusplus +# define progn(...) ([&]() -> decltype(auto) { __VA_ARGS__ }()) +# define eval_once(expr) eval_once2(expr, __COUNTER__) +# define eval_once2(expr, ctr) ([&] { [[maybe_unused]] static auto init ## ctr = (((void)(expr)), 0); }()) +#endif -- cgit v1.2.3