From 6aa0422e8529d76385b64f0a826f5ffd353fd37b Mon Sep 17 00:00:00 2001 From: kosak Date: Mon, 17 Nov 2014 00:27:28 +0000 Subject: [PATCH] Distinguish between C++11 language and library support for std::function, std::begin, std::end, and std::move in gtest and gmock. --- include/gtest/internal/gtest-port.h | 34 ++++++++++++++++++++++++----- test/gtest-printers_test.cc | 2 +- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index f376dfa0..17220a5a 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -377,12 +377,34 @@ # endif #endif -// C++11 specifies that provides std::initializer_list. Use -// that if gtest is used in C++11 mode and libstdc++ isn't very old (binaries -// targeting OS X 10.6 can build with clang but need to use gcc4.2's -// libstdc++). -#if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325) +// Distinct from C++11 language support, some environments don't provide +// proper C++11 library support. Notably, it's possible to build in +// C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++ +// with no C++11 support. +// +// libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__ +// 20110325, but maintenance releases in the 4.4 and 4.5 series followed +// this date, so check for those versions by their date stamps. +// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning +#if GTEST_LANG_CXX11 && \ + (!defined(__GLIBCXX__) || ( \ + __GLIBCXX__ >= 20110325ul && /* GCC >= 4.6.0 */ \ + /* Blacklist of patch releases of older branches: */ \ + __GLIBCXX__ != 20110416ul && /* GCC 4.4.6 */ \ + __GLIBCXX__ != 20120313ul && /* GCC 4.4.7 */ \ + __GLIBCXX__ != 20110428ul && /* GCC 4.5.3 */ \ + __GLIBCXX__ != 20120702ul)) /* GCC 4.5.4 */ +# define GTEST_STDLIB_CXX11 1 +#endif + +// Only use C++11 library features if the library provides them. +#if GTEST_STDLIB_CXX11 +# define GTEST_HAS_STD_BEGIN_AND_END_ 1 +# define GTEST_HAS_STD_FORWARD_LIST_ 1 +# define GTEST_HAS_STD_FUNCTION_ 1 # define GTEST_HAS_STD_INITIALIZER_LIST_ 1 +# define GTEST_HAS_STD_MOVE_ 1 +# define GTEST_HAS_STD_UNIQUE_PTR_ 1 #endif // C++11 specifies that provides std::tuple. @@ -883,7 +905,7 @@ using ::std::tuple_size; # define GTEST_MUST_USE_RESULT_ #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC -#if GTEST_LANG_CXX11 +#if GTEST_HAS_STD_MOVE_ # define GTEST_MOVE_(x) ::std::move(x) // NOLINT #else # define GTEST_MOVE_(x) x diff --git a/test/gtest-printers_test.cc b/test/gtest-printers_test.cc index 7b07fd10..562a0a9a 100644 --- a/test/gtest-printers_test.cc +++ b/test/gtest-printers_test.cc @@ -1037,7 +1037,7 @@ TEST(PrintTr1TupleTest, NestedTuple) { #endif // GTEST_HAS_TR1_TUPLE -#if GTEST_LANG_CXX11 +#if GTEST_HAS_STD_TUPLE_ // Tests printing ::std::tuples. // Tuples of various arities.