Skip to content

Commit 77e0e9e

Browse files
committed
Reapply "Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories."
add_compile_options is more sensitive to its location in the file than add_definitions--it only takes effect for sources that are added after it. This updated patch ensures that the add_compile_options is done before adding any source files that depend on it. Using add_definitions caused the flag to be passed to rc.exe on Windows and thus broke Windows builds.
1 parent ebe5f17 commit 77e0e9e

File tree

18 files changed

+72
-1
lines changed

18 files changed

+72
-1
lines changed

clang-tools-extra/clangd/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ include_directories(
1313
${CLANGD_BINARY_DIR}
1414
)
1515

16+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
17+
add_compile_options("-Wno-suggest-override")
18+
endif()
19+
1620
if(CLANG_BUILT_STANDALONE)
1721
# LLVMTestingSupport library is needed for clangd tests.
1822
if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support

clang-tools-extra/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ function(add_extra_unittest test_dirname)
55
add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
66
endfunction()
77

8+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
9+
add_compile_options("-Wno-suggest-override")
10+
endif()
11+
812
add_subdirectory(clang-apply-replacements)
913
add_subdirectory(clang-change-namespace)
1014
add_subdirectory(clang-doc)

clang/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
add_custom_target(ClangUnitTests)
22
set_target_properties(ClangUnitTests PROPERTIES FOLDER "Clang tests")
33

4+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
5+
add_compile_options("-Wno-suggest-override")
6+
endif()
7+
48
if(CLANG_BUILT_STANDALONE)
59
# LLVMTestingSupport library is needed for some of the unittests.
610
if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support

compiler-rt/cmake/Modules/AddCompilerRT.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ set(COMPILER_RT_GMOCK_CFLAGS
403403

404404
append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)
405405
append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
406+
append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS)
406407

407408
if(MSVC)
408409
# gtest use a lot of stuff marked as deprecated on Windows.

compiler-rt/cmake/config-ix.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" COMPILER_RT_HAS_WNON_VIRT
106106
check_cxx_compiler_flag("-Werror -Wvariadic-macros" COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
107107
check_cxx_compiler_flag("-Werror -Wunused-parameter" COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG)
108108
check_cxx_compiler_flag("-Werror -Wcovered-switch-default" COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG)
109+
check_cxx_compiler_flag("-Werror -Wsuggest-override" COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG)
109110
check_cxx_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
110111

111112
check_cxx_compiler_flag(/W4 COMPILER_RT_HAS_W4_FLAG)

flang/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ function(add_flang_unittest test_dirname)
55
add_unittest(FlangUnitTests ${test_dirname} ${ARGN})
66
endfunction()
77

8+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
9+
add_compile_options("-Wno-suggest-override")
10+
endif()
11+
812
add_subdirectory(Optimizer)
913
add_subdirectory(Decimal)
1014
add_subdirectory(Evaluate)

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)

lld/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ function(add_lld_unittest test_dirname)
1212
target_link_libraries(${test_dirname} ${LLVM_COMMON_LIBS})
1313
endfunction()
1414

15+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
16+
add_compile_options("-Wno-suggest-override")
17+
endif()
18+
1519
add_subdirectory(DriverTests)
1620
add_subdirectory(MachOTests)

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_compile_options("-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

+15
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,21 @@ 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 it's available, and only if it doesn't
676+
# suggest adding 'override' to functions that are already marked 'final'
677+
# (which means it is disabled for GCC < 9.2).
678+
check_cxx_compiler_flag("-Wsuggest-override" CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
679+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
680+
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
681+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=suggest-override")
682+
CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();};
683+
class derived : base {public: void anchor() final;};
684+
int main() { return 0; }"
685+
CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL)
686+
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
687+
append_if(CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL "-Wsuggest-override" CMAKE_CXX_FLAGS)
688+
endif()
689+
675690
# Check if -Wcomment is OK with an // comment ending with '\' if the next
676691
# line is also a // comment.
677692
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})

llvm/lib/Testing/Support/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
add_definitions(-DGTEST_LANG_CXX11=1)
22
add_definitions(-DGTEST_HAS_TR1_TUPLE=0)
33

4+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
5+
add_compile_options("-Wno-suggest-override")
6+
endif()
7+
48
add_llvm_library(LLVMTestingSupport
59
Annotations.cpp
610
Error.cpp

llvm/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function(add_llvm_target_unittest test_dir_name)
1414
add_llvm_unittest(${test_dir_name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
1515
endfunction()
1616

17+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
18+
add_compile_options("-Wno-suggest-override")
19+
endif()
20+
1721
add_subdirectory(ADT)
1822
add_subdirectory(Analysis)
1923
add_subdirectory(AsmParser)

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 )

mlir/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ function(add_mlir_unittest test_dirname)
55
add_unittest(MLIRUnitTests ${test_dirname} ${ARGN})
66
endfunction()
77

8+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
9+
add_compile_options("-Wno-suggest-override")
10+
endif()
11+
812
add_subdirectory(Analysis)
913
add_subdirectory(Dialect)
1014
add_subdirectory(IR)

parallel-libs/acxxel/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
3636

3737
# Add warning flags.
3838
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
39+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
40+
add_compile_options("-Wno-suggest-override")
41+
endif()
3942

4043
add_library(
4144
acxxel

polly/unittests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function(add_polly_unittest test_name)
1919
target_link_libraries(${test_name} PRIVATE Polly)
2020
endfunction()
2121

22+
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
23+
add_compile_options("-Wno-suggest-override")
24+
endif()
25+
2226
add_subdirectory(Isl)
2327
add_subdirectory(Flatten)
2428
add_subdirectory(DeLICM)

0 commit comments

Comments
 (0)