From e26188145238572580b9af18fbde4b824b341046 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 29 Sep 2015 14:19:47 +0200 Subject: Avoid unhelpful -Wunused-variable ...at least from "g++ (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)" with --disable-debug, when a namespace-scope const variable with a "complex" initializer declared in an include file remains unused. Avoid that warning via SAL_CONSTEXPR, which in turn requires large parts of o3tl::is_typed_flags to be SAL_CONSTEXPR, which in turn requires a new HAVE_CXX14_CONSTEXPR to allow assert in constexpr functions, which in turn requires using -std=c++14 instead of -std=c++11 where available, which in turn (a) requires to /not/ use -std=c++14 if it would run into a bug between Clang and libstdc++ discussed at "llvm-nm fails to build with gcc 5.1's libstdc++" (and which hits us in sfx2/source/control/thumbnailview.cxx), and (b) requires a new HAVE_CXX14_SIZED_DEALLOCATION to work around GCC 5.1 -Werror=sized-deallocation (where Clang >= 3.7 only supports C++14 sized deallocation when explictly enabled via -fsized-deallocation, btw). This effectively reverts ff6462e6307e6924dc6c8178043ae9032f4b4152 "avoid unused variable warning:" again. Change-Id: I424e3561452a3e6d8c8a9604d6c737cab49840c4 Reviewed-on: https://gerrit.libreoffice.org/18918 Reviewed-by: Stephan Bergmann Tested-by: Stephan Bergmann --- include/o3tl/typed_flags_set.hxx | 73 +++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 20 deletions(-) (limited to 'include/o3tl') diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx index 4755c09fb536..9b8cb817ee02 100644 --- a/include/o3tl/typed_flags_set.hxx +++ b/include/o3tl/typed_flags_set.hxx @@ -25,18 +25,21 @@ #include #include +#include +#include + namespace o3tl { namespace detail { -template inline +template inline SAL_CONSTEXPR typename std::enable_if::value, bool>::type isNonNegative( T value) { return value >= 0; } -template inline +template inline SAL_CONSTEXPR typename std::enable_if::value, bool>::type isNonNegative(T) { return true; @@ -70,19 +73,23 @@ struct is_typed_flags { public: typedef is_typed_flags Unwrapped; - explicit Wrap(typename std::underlying_type::type value): + explicit SAL_CONSTEXPR Wrap( + typename std::underlying_type::type value): value_(value) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert(detail::isNonNegative(value)); assert((value & ~M) == 0); +#endif } - operator E() { return static_cast(value_); } + SAL_CONSTEXPR operator E() const { return static_cast(value_); } - explicit operator typename std::underlying_type::type() + explicit SAL_CONSTEXPR operator typename std::underlying_type::type() + const { return value_; } - explicit operator bool() { return value_ != 0; } + explicit SAL_CONSTEXPR operator bool() const { return value_ != 0; } private: typename std::underlying_type::type value_; @@ -94,17 +101,19 @@ struct is_typed_flags { } template -inline typename o3tl::typed_flags::Wrap operator ~(E rhs) { +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator ~(E rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( o3tl::typed_flags::mask & ~static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator ~( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator ~( typename o3tl::typed_flags::Wrap rhs) { return static_cast::Wrap>( @@ -113,44 +122,53 @@ inline typename o3tl::typed_flags::Wrap operator ~( } template -inline typename o3tl::typed_flags::Wrap operator ^(E lhs, E rhs) { +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator ^( + E lhs, E rhs) +{ +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(lhs))); assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) ^ static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator ^( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator ^( E lhs, typename o3tl::typed_flags::Wrap rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(lhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) ^ static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator ^( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator ^( typename o3tl::typed_flags::Wrap lhs, E rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) ^ static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator ^( +inline SAL_CONSTEXPR +typename o3tl::typed_flags::Wrap operator ^( W lhs, W rhs) { return static_cast( @@ -163,44 +181,53 @@ inline typename o3tl::typed_flags::Wrap operator ^( } template -inline typename o3tl::typed_flags::Wrap operator &(E lhs, E rhs) { +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator &( + E lhs, E rhs) +{ +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(lhs))); assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) & static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator &( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator &( E lhs, typename o3tl::typed_flags::Wrap rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(lhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) & static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator &( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator &( typename o3tl::typed_flags::Wrap lhs, E rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) & static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator &( +inline SAL_CONSTEXPR +typename o3tl::typed_flags::Wrap operator &( W lhs, W rhs) { return static_cast( @@ -213,44 +240,50 @@ inline typename o3tl::typed_flags::Wrap operator &( } template -inline typename o3tl::typed_flags::Wrap operator |(E lhs, E rhs) { +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator |(E lhs, E rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(lhs))); assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) | static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator |( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator |( E lhs, typename o3tl::typed_flags::Wrap rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(lhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) | static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator |( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator |( typename o3tl::typed_flags::Wrap lhs, E rhs) { +#if !HAVE_CXX11_CONSTEXPR || HAVE_CXX14_CONSTEXPR assert( o3tl::detail::isNonNegative( static_cast::type>(rhs))); +#endif return static_cast::Wrap>( static_cast::type>(lhs) | static_cast::type>(rhs)); } template -inline typename o3tl::typed_flags::Wrap operator |( +inline SAL_CONSTEXPR typename o3tl::typed_flags::Wrap operator |( W lhs, W rhs) { return static_cast( -- cgit v1.2.3