Skip to content

Commit dc1d094

Browse files
davezarzyckijrose-apple
authored andcommitted
[CMake] Infer -Werror=switch via asserts being enabled (#11098)
LLVM-style projects like Swift make heavy use of switch statements and therefore -Werror=switch is very useful during feature development. That being said, if asserts are disabled, then you're probably not actively hacking on the project and -Werror (or warnings in general) aren't helpful.
1 parent dc4bc16 commit dc1d094

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ endmacro()
256256
# Common cmake project config for additional warnings.
257257
#
258258
macro(swift_common_cxx_warnings)
259+
# Make unhandled switch cases be an error in assert builds
260+
if(DEFINED LLVM_ENABLE_ASSERTIONS)
261+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=switch")
262+
endif()
263+
259264
check_cxx_compiler_flag("-Werror -Wdocumentation" CXX_SUPPORTS_DOCUMENTATION_FLAG)
260265
append_if(CXX_SUPPORTS_DOCUMENTATION_FLAG "-Wdocumentation" CMAKE_CXX_FLAGS)
261266

0 commit comments

Comments
 (0)