Skip to content

Commit 8b16e45

Browse files
committed
Enable -Wsuggest-override in the LLVM build
This patch adds Clang's new (and GCC's old) -Wsuggest-override to the warning flags for the LLVM build. The warning is a stronger form of -Winconsistent-missing-override which warns _everywhere_ that override is missing, not just in places where it's inconsistent within a class. Some directories in the monorepo need the warning disabled for compatibility's, or sanity's, sake; in particular, libcxx/libcxxabi, and any code implementing or interoperating with googletest, googlemock, or google benchmark (which do not themselves use override). This patch adds -Wno-suggest-override to the relevant CMakeLists.txt's to accomplish this. Differential Revision: https://reviews.llvm.org/D84126
1 parent 9f5d8e8 commit 8b16e45

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

libcxx/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ function(cxx_add_warning_flags target)
578578
target_add_compile_flags_if_supported(${target} PRIVATE
579579
-Wno-user-defined-literals
580580
-Wno-covered-switch-default
581+
-Wno-suggest-override
581582
-Wno-ignored-attributes # FIXME: Caused by _LIBCPP_NODEBUG_TYPE not being supported on older clangs
582583
)
583584
if (LIBCXX_TARGETING_CLANG_CL)
@@ -602,7 +603,8 @@ function(cxx_add_warning_flags target)
602603
target_add_compile_flags_if_supported(${target} PRIVATE
603604
-Wno-literal-suffix
604605
-Wno-c++14-compat
605-
-Wno-noexcept-type)
606+
-Wno-noexcept-type
607+
-Wno-suggest-override)
606608
endif()
607609
if (LIBCXX_ENABLE_WERROR)
608610
target_add_compile_flags_if_supported(${target} PRIVATE -Werror)

libcxxabi/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ add_compile_flags_if_supported(-Wunused-variable)
283283
add_compile_flags_if_supported(-Wwrite-strings)
284284
add_compile_flags_if_supported(-Wundef)
285285

286+
add_compile_flags_if_supported(-Wno-suggest-override)
287+
286288
if (LIBCXXABI_ENABLE_WERROR)
287289
add_compile_flags_if_supported(-Werror)
288290
add_compile_flags_if_supported(-WX)

lldb/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ add_dependencies(lldb-test-deps LLDBUnitTests)
55
include_directories(${LLDB_SOURCE_ROOT})
66
include_directories(${LLDB_PROJECT_ROOT}/unittests)
77

8+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
9+
add_definitions("-Wno-suggest-override")
10+
endif()
11+
812
set(LLDB_GTEST_COMMON_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/gtest_common.h)
913
if (MSVC)
1014
list(APPEND LLVM_COMPILE_FLAGS /FI ${LLDB_GTEST_COMMON_INCLUDE})

llvm/cmake/modules/HandleLLVMOptions.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
672672
# Enable -Wdelete-non-virtual-dtor if available.
673673
add_flag_if_supported("-Wdelete-non-virtual-dtor" DELETE_NON_VIRTUAL_DTOR_FLAG)
674674

675+
# Enable -Wsuggest-override if available.
676+
add_flag_if_supported("-Wsuggest-override" SUGGEST_OVERRIDE_FLAG)
677+
675678
# Check if -Wcomment is OK with an // comment ending with '\' if the next
676679
# line is also a // comment.
677680
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})

llvm/utils/benchmark/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ else()
156156
add_cxx_compiler_flag(-fno-exceptions)
157157
endif()
158158

159+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
160+
add_cxx_compiler_flag(-Wno-suggest-override)
161+
endif()
162+
159163
if (HAVE_CXX_FLAG_FSTRICT_ALIASING)
160164
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel") #ICC17u2: Many false positives for Wstrict-aliasing
161165
add_cxx_compiler_flag(-Wstrict-aliasing)

llvm/utils/unittest/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ endif()
4343
if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
4444
add_definitions("-Wno-covered-switch-default")
4545
endif()
46+
if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
47+
add_definitions("-Wno-suggest-override")
48+
endif()
4649

4750
set(LLVM_REQUIRES_RTTI 1)
4851
add_definitions( -DGTEST_HAS_RTTI=0 )

0 commit comments

Comments
 (0)