diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 2e5388945..231e0ccc6 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -222,6 +222,7 @@ if (gtest_build_tests) cxx_test(gtest-unittest-api_test gtest) cxx_test(gtest_skip_in_environment_setup_test gtest_main) cxx_test(gtest_skip_test gtest_main) + cxx_test(gtest_compare_lib_detection_test gtest_main) ############################################################ # C++ tests built with non-standard compiler flags. diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index b607e0ade..650a04558 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2411,9 +2411,7 @@ using StringView = ::std::string_view; #define GTEST_INTERNAL_HAS_STRING_VIEW 0 #endif -#if (defined(__cpp_lib_three_way_comparison) || \ - (GTEST_INTERNAL_HAS_INCLUDE() && \ - GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L)) +#if defined(__cpp_lib_three_way_comparison) #define GTEST_INTERNAL_HAS_COMPARE_LIB 1 #else #define GTEST_INTERNAL_HAS_COMPARE_LIB 0 diff --git a/googletest/test/gtest_compare_lib_detection_test.cc b/googletest/test/gtest_compare_lib_detection_test.cc new file mode 100644 index 000000000..f44b79a5f --- /dev/null +++ b/googletest/test/gtest_compare_lib_detection_test.cc @@ -0,0 +1,54 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Regression test for https://github.com/google/googletest/issues/4933. +// +// Verifies that GTEST_INTERNAL_HAS_COMPARE_LIB is set to 1 if and only if +// the standard feature test macro __cpp_lib_three_way_comparison is defined. +// The macro must NOT use a fallback based on the mere presence of the +// header and C++ language version, because some toolchains +// (e.g. Android NDK 24/25 with Clang 14) ship an incomplete +// header that lacks the comparison operators required by gtest-printers. + +#include "gtest/internal/gtest-port.h" + +#ifdef __cpp_lib_three_way_comparison +static_assert( + GTEST_INTERNAL_HAS_COMPARE_LIB == 1, + "GTEST_INTERNAL_HAS_COMPARE_LIB should be 1 when " + "__cpp_lib_three_way_comparison is defined"); +#else +static_assert( + GTEST_INTERNAL_HAS_COMPARE_LIB == 0, + "GTEST_INTERNAL_HAS_COMPARE_LIB should be 0 when " + "__cpp_lib_three_way_comparison is not defined. " + "See https://github.com/google/googletest/issues/4933"); +#endif + +int main() { return 0; }