diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/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)