[PATCH] D84292: Only enable -Wsuggest-override if it doesn't suggest adding override to functions that are already final

Logan Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 10:06:27 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG274b6b0c7a8b: Only enable -Wsuggest-override if it doesn't suggest adding override to… (authored by logan-5).

Changed prior to commit:
  https://reviews.llvm.org/D84292?vs=279701&id=279869#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84292/new/

https://reviews.llvm.org/D84292

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -672,8 +672,20 @@
   # Enable -Wdelete-non-virtual-dtor if available.
   add_flag_if_supported("-Wdelete-non-virtual-dtor" DELETE_NON_VIRTUAL_DTOR_FLAG)
 
-  # Enable -Wsuggest-override if available.
-  add_flag_if_supported("-Wsuggest-override" SUGGEST_OVERRIDE_FLAG)
+  # Enable -Wsuggest-override if it's available, and only if it doesn't
+  # suggest adding 'override' to functions that are already marked 'final'
+  # (which means it is disabled for GCC < 9.2).
+  check_cxx_compiler_flag("-Wsuggest-override" CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+  if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
+    set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=suggest-override")
+    CHECK_CXX_SOURCE_COMPILES("class base {public: virtual void anchor();};
+                               class derived : base {public: void anchor() final;};
+                               int main() { return 0; }"
+                              CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL)
+    set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+    append_if(CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL "-Wsuggest-override" CMAKE_CXX_FLAGS)
+  endif()
 
   # Check if -Wcomment is OK with an // comment ending with '\' if the next
   # line is also a // comment.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84292.279869.patch
Type: text/x-patch
Size: 1516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200722/c881c607/attachment.bin>


More information about the llvm-commits mailing list