Skip to content

Commit b5b702e

Browse files
committed
[Stdlib] Enable -Wformat-nonliteral and make it an error.
Turn on -Wformat-nonliteral so that any format string that is passed through a variable is turned into an error. There are a variety of reasonable ways of fixing these where they occur, and it's safer to have this switched on. rdar://84571859
1 parent 920bcc2 commit b5b702e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

stdlib/public/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
3838
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-xc++")
3939
endif()
4040

41+
# We should avoid non-literals in format strings, or appropriately mark
42+
# functions.
43+
check_cxx_compiler_flag("-Wformat-nonliteral -Werror=format-nonliteral" CXX_SUPPORTS_FORMAT_NONLITERAL_WARNING)
44+
if (CXX_SUPPORTS_FORMAT_NONLITERAL_WARNING)
45+
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wformat-nonliteral"
46+
"-Werror=format-nonliteral")
47+
endif()
48+
4149
# C++ code in the runtime and standard library should generally avoid
4250
# introducing static constructors or destructors.
4351
check_cxx_compiler_flag("-Wglobal-constructors -Werror=global-constructors" CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)

0 commit comments

Comments
 (0)