From 90b1f084bf0998e37ad3fa9f54641656044c448f Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 21 Dec 2014 20:19:12 +0100 Subject: [PATCH] Improve C++11 support If we compile in C++11 mode, do not use the boost replacements for bind, functional and shared_ptr. regex is excluded, since it misses match_partial, and gcc does not provide a usable one in versions less than 4.9.0. I also removed the #define for match_partial, since this is dangerous. Now you get a compile error instead of subtle runtime differences. --- CMakeLists.txt | 2 ++ configure.ac | 2 ++ src/support/bind.h | 23 ++++++++++++++++++----- src/support/functional.h | 17 +++++++++++------ src/support/regex.h | 14 ++++++++++++-- src/support/shared_ptr.h | 20 ++++++++++++-------- 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0db64f7341..86f6a01806 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,6 +250,8 @@ if(UNIX OR MINGW) set(LYX_USE_TR1 1) # GCC <= 4.5 does not support regex: there are linker errors # http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.tr1 + # and in gcc are unusable in versions less than 4.9.0 + # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 set(LYX_USE_TR1_REGEX 0) endif() if (LYX_ENABLE_CXX11) diff --git a/configure.ac b/configure.ac index 1cbb6bd978..562eba4d9b 100644 --- a/configure.ac +++ b/configure.ac @@ -285,6 +285,8 @@ char * strerror(int n); #define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1 // TR1 regex not supported in GCC <= 4.5 +// and in gcc are unusable in versions less than 4.9.0 +// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 // clang defines __GNUC__ but libc++ does not have tr1 #ifndef LYX_USE_TR1 # if __GNUC__ == 4 && !defined(USE_LLVM_LIBCPP) diff --git a/src/support/bind.h b/src/support/bind.h index efd3267de5..1931b163ec 100644 --- a/src/support/bind.h +++ b/src/support/bind.h @@ -16,25 +16,38 @@ #ifdef LYX_USE_TR1 +#define LYX_BIND_NS std::tr1 + namespace lyx { - using std::tr1::bind; using std::tr1::placeholders::_1; using std::tr1::placeholders::_2; - using std::tr1::ref; +} + +#elif __cplusplus >= 201103L + +#define LYX_BIND_NS std + +namespace lyx +{ + using std::placeholders::_1; + using std::placeholders::_2; } #else #include +#define LYX_BIND_NS boost + +#endif namespace lyx { - using boost::bind; - using boost::ref; + using LYX_BIND_NS::bind; + using LYX_BIND_NS::ref; } -#endif +#undef LYX_BIND_NS #endif diff --git a/src/support/functional.h b/src/support/functional.h index 47d9c45966..bb60029611 100644 --- a/src/support/functional.h +++ b/src/support/functional.h @@ -20,22 +20,27 @@ #include #endif -namespace lyx -{ - using std::tr1::function; -} +#define LYX_FUNCTIONAL_NS std::tr1 + +#elif __cplusplus >= 201103L + +#include +#define LYX_FUNCTIONAL_NS std #else #include #include +#define LYX_FUNCTIONAL_NS boost + +#endif namespace lyx { - using boost::function; + using LYX_FUNCTIONAL_NS::function; } -#endif +#undef LYX_FUNCTIONAL_NS #endif diff --git a/src/support/regex.h b/src/support/regex.h index 96d6836e23..eb3b679a80 100644 --- a/src/support/regex.h +++ b/src/support/regex.h @@ -58,8 +58,7 @@ namespace lyx { } # else # include -// TODO no match_partial in gcc, how to replace? -# define match_partial match_default +// TODO no match_partial in TR1, how to replace? # endif # define LR_NS std::tr1 namespace lyx { @@ -67,6 +66,17 @@ using LR_NS::regex; using LR_NS::regex_match; using LR_NS::sregex_iterator; } +#elif LYX_USE_TR1_REGEX +# include +// in gcc is unusable in versions less than 4.9.0 +// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 +// TODO no match_partial in std, how to replace? +# define LR_NS std +namespace lyx { +using LR_NS::regex; +using LR_NS::regex_match; +using LR_NS::sregex_iterator; +} #else # include # define LR_NS boost diff --git a/src/support/shared_ptr.h b/src/support/shared_ptr.h index 69e42da23c..874a6cde91 100644 --- a/src/support/shared_ptr.h +++ b/src/support/shared_ptr.h @@ -20,23 +20,27 @@ #include #endif -namespace lyx -{ - using std::tr1::shared_ptr; - using std::tr1::const_pointer_cast; -} +#define LYX_SHAREDPTR_NS std::tr1 + +#elif __cplusplus >= 201103L + +#include +#define LYX_SHAREDPTR_NS std #else #include +#define LYX_SHAREDPTR_NS boost + +#endif namespace lyx { - using boost::shared_ptr; - using boost::const_pointer_cast; + using LYX_SHAREDPTR_NS::shared_ptr; + using LYX_SHAREDPTR_NS::const_pointer_cast; } -#endif +#undef LYX_SHAREDPTR_NS #endif