Skip to content

Commit 3d21b56

Browse files
committed
[GTest][c++17] Silence warnings when building GTest with gcc-toolset-12
This change fixes a build break introduced by aafad2d(#70353) on the clang-ppc64le-rhel build bot. If the third-party Google Test suite is built using gcc-toolset-12, the implementation of std::stable_sort in the toolchain will use a get_temporary_buffer declaration that is marked _GLIBCXX17_DEPRECATED. This change adds -Wno-deprecated-declarations to the GTest flags if the toolchain is detected in the build compiler on linux.
1 parent 33af16f commit 3d21b56

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,24 @@ endif()
678678
append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)
679679
append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
680680
append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS)
681-
682-
if(MSVC)
683-
# gtest use a lot of stuff marked as deprecated on Windows.
681+
# Detect if the compiler toolchain includes gcc-toolset-12.
682+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR
683+
"${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
684+
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
685+
RESULT_VARIABLE compiler_info_rc
686+
OUTPUT_VARIABLE compiler_info
687+
ERROR_VARIABLE compiler_info)
688+
if(compiler_info MATCHES ".*gcc-toolset-12.*")
689+
set(USING_GCC_TOOLSET_12 TRUE)
690+
endif()
691+
endif()
692+
if(MSVC OR (LINUX AND DEFINED USING_GCC_TOOLSET_12 AND
693+
CMAKE_CXX_STANDARD EQUAL 17))
694+
# gtest use a lot of stuff marked as deprecated on Windows or if using
695+
# gcc-toolset-12 in the compiler toolchain on Linux; all of the
696+
# deprecated declarations in gcc-toolset-12 used in Google Tests have been
697+
# observed to be _GLIBCXX17_DEPRECATED and should go away once
698+
# CMAKE_CXX_STANDARD is greater than 17.
684699
list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
685700
endif()
686701

0 commit comments

Comments
 (0)