diff options
author | Christoph Lutz <christoph.lutz_ml@cib.de> | 2015-05-07 13:47:35 +0200 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2015-05-07 14:10:51 +0000 |
commit | 7ad4e562b462af22a1c29c955293238cdb30267b (patch) | |
tree | 7940de00e7fba7d572f26b0f791abf1c79d7a0f5 | |
parent | 6a26624d8ba9d37481e75f5c952dff9c6dd86fb6 (diff) |
improve fallback behaviour of underlying_type for old gcc
The fix fbd85c25b is not sufficient to build with an old GCC 4.6.
The problem was, that underlying_type returned an int as default
value for GCC 4.6 and int allows negative values that are forbidden
in typed_flags_set.
Changed it to alternative solution suggested in
http://stackoverflow.com/questions/26148192/underlying-type-of-a-c-enum-in-c03
Change-Id: I20f44b8cef9c692efb583971bd251f1c34c289ab
Reviewed-on: https://gerrit.libreoffice.org/15663
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Tested-by: Katarina Behrens <Katarina.Behrens@cib.de>
-rw-r--r-- | include/o3tl/underlying_type.hxx | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/include/o3tl/underlying_type.hxx b/include/o3tl/underlying_type.hxx index 4b2e0778ee60..534e0883fc7e 100644 --- a/include/o3tl/underlying_type.hxx +++ b/include/o3tl/underlying_type.hxx @@ -19,7 +19,11 @@ namespace o3tl { template<typename T> struct underlying_type { #if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ <= 6 && \ !defined __clang__ - typedef int type; + typedef typename std::conditional< + T( -1 ) < T( 0 ), + typename std::make_signed< T >::type, + typename std::make_unsigned< T >::type + >::type type; #else typedef typename std::underlying_type<T>::type type; #endif |