[PATCH] D99825: [cmake] Enable -Werror=return-type for clang

Dave Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 2 17:58:36 PDT 2021


kastiglione created this revision.
kastiglione added reviewers: vsk, JDevlieghere, xbolva00.
Herald added a subscriber: mgorny.
kastiglione requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Follow up to D98224 <https://reviews.llvm.org/D98224>, but making this an error only for clang.

As mentioned in the comments, gcc basically doesn't support the notion of
exhasutive switches over enums. After initially commiting D98224 <https://reviews.llvm.org/D98224>, downstream
compilation errors resulted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99825

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -758,6 +758,16 @@
 
   # Enable -Wstring-conversion to catch misuse of string literals.
   add_flag_if_supported("-Wstring-conversion" STRING_CONVERSION_FLAG)
+
+  # Disabled for gcc. Clang and gcc differ in handling of switch statements
+  # that exhaustively handle all enumerations. This diagnostic is emitted by
+  # gcc in such cases, while clang does not. For gcc, exhaustive switch
+  # statements must be followed by a return statement or llvm_unreachable().
+  if (NOT CMAKE_COMPILER_IS_GNUCXX)
+    # Enable -Werror=return-type if available, to catch functions that contain
+    # control paths that do not return a value.
+    add_flag_if_supported("-Werror=return-type" WERROR_RETURN_TYPE)
+  endif()
 endif (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
 
 if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT LLVM_ENABLE_WARNINGS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99825.335051.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210403/acfd4257/attachment.bin>


More information about the llvm-commits mailing list