summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorDylan Noblesmith <nobled@dreamwidth.org>2014-08-23 21:10:56 +0000
committerDylan Noblesmith <nobled@dreamwidth.org>2014-08-23 21:10:56 +0000
commit136fd4c7e245447783fb49b430d3dc6ee2a7d65e (patch)
treeecbd2f760aa0de75e1062c9739b28aa578409723 /cmake
parent8eb867e97d880b958b96dcc57b92076acf1d625f (diff)
cmake: disable -Wnon-virtual-dtor when it gives false positives
clang has only been smart enough not to trigger -Wnon-virtual-dtor warnings on final classes since r208449 (in clang 3.5). Building with older versions is extremely noisy, so disable the warning on those compilers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216327 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/HandleLLVMOptions.cmake16
1 files changed, 14 insertions, 2 deletions
diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
index b872864eb6b..d9c68999fb0 100644
--- a/cmake/modules/HandleLLVMOptions.cmake
+++ b/cmake/modules/HandleLLVMOptions.cmake
@@ -288,8 +288,20 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG)
append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
- check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG)
- append_if(CXX_SUPPORTS_NON_VIRTUAL_DTOR_FLAG "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
+
+ # Check if -Wnon-virtual-dtor warns even though the class is marked final.
+ # If it does, don't add it. So it won't be added on clang 3.4 and older.
+ # This also catches cases when -Wnon-virtual-dtor isn't supported by
+ # the compiler at all.
+ set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11 -Werror=non-virtual-dtor")
+ CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();protected: ~base();};
+ class derived final : public base { public: ~derived();};
+ int main() { return 0; }"
+ CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR)
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+ append_if(CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR
+ "-Wnon-virtual-dtor" CMAKE_CXX_FLAGS)
# Check if -Wcomment is OK with an // comment ending with '\' if the next
# line is also a // comment.