Skip to content

Commit 6ccfe03

Browse files
committed
[Runtime] Static constructors and destructors should be an error here.
Except for a handful of places we know about, there should be no static constructors or destructors in the runtime; they're undesirable because they inflate start up or shut down times, and in the case of destructors we can't even guarantee that they will actually run (e.g. if the program declares that it supports fast termination, they just won't). It should be OK to change the warnings to errors as a result. rdar://80965245
1 parent c965f34 commit 6ccfe03

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stdlib/public/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ endif()
4141

4242
# C++ code in the runtime and standard library should generally avoid
4343
# introducing static constructors or destructors.
44-
check_cxx_compiler_flag("-Werror -Wglobal-constructors" CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
44+
check_cxx_compiler_flag("-Wglobal-constructors -Werror=global-constructors" CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
4545
if(CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
46-
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wglobal-constructors")
46+
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wglobal-constructors"
47+
"-Werror=global-constructors")
4748
endif()
4849

4950
# C++ code in the runtime and standard library should generally avoid
5051
# introducing static constructors or destructors.
51-
check_cxx_compiler_flag("-Wexit-time-destructors" CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
52+
check_cxx_compiler_flag("-Wexit-time-destructors -Werror=exit-time-destructors" CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
5253
if(CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
53-
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wexit-time-destructors")
54+
list(APPEND SWIFT_RUNTIME_CORE_CXX_FLAGS "-Wexit-time-destructors"
55+
"-Werror=exit-time-destructors")
5456
endif()
5557

5658
add_subdirectory(SwiftShims)

0 commit comments

Comments
 (0)