From 6b5535e915f65a64f201bdb6ca4d9e36ece8c12b Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Wed, 8 Oct 2025 14:47:57 +0100 Subject: [PATCH] [cxx-interop] Do not warn for implicit default constructors The diagnostic that Swift was emitting (`This zero-initializes the backing memory of the struct ...`) was flaky, because it was only emitted when the default constructor of a C++ struct was instantiated by Swift. If it was instantiated by Clang, the diagnostic wasn't emitted. There is not a lot of value in it. Let's make the behavior consistent by removing the diagnostic. rdar://161999293 --- lib/ClangImporter/ImportDecl.cpp | 9 --------- .../class/inheritance/functions-module-interface.swift | 3 --- .../Cxx/objc-correctness/pthread_mutexattr_t.swift | 2 +- .../Cxx/templates/enable-if-module-interface.swift | 1 - 4 files changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 0627a8e5ed4ee..89a59dc397276 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -2544,15 +2544,6 @@ namespace { // constructor available in Swift. ConstructorDecl *defaultCtor = synthesizer.createDefaultConstructor(result); - if (cxxRecordDecl) { - auto attr = AvailableAttr::createUniversallyDeprecated( - defaultCtor->getASTContext(), - "This zero-initializes the backing memory of the struct, which " - "is unsafe for some C++ structs. Consider adding an explicit " - "default initializer for this C++ struct.", - ""); - defaultCtor->getAttrs().add(attr); - } ctors.push_back(defaultCtor); } diff --git a/test/Interop/Cxx/class/inheritance/functions-module-interface.swift b/test/Interop/Cxx/class/inheritance/functions-module-interface.swift index 4ca095c4a7a20..74a7bf2b158f5 100644 --- a/test/Interop/Cxx/class/inheritance/functions-module-interface.swift +++ b/test/Interop/Cxx/class/inheritance/functions-module-interface.swift @@ -136,7 +136,6 @@ // CHECK-NEXT: public func getCopyCounter() -> UnsafeMutablePointer // CHECK-NEXT: public struct CopyTrackedBaseClass { // CHECK-NEXT: public init(_ x: Int32) -// CHECK-NEXT: @available(*, deprecated, message: "This zero-initializes the backing memory of the struct, which is unsafe for some C++ structs. Consider adding an explicit default initializer for this C++ struct.") // CHECK-NEXT: @_transparent public init() // CHECK-NEXT: @discardableResult // CHECK-NEXT: public func getX() -> Int32 @@ -147,7 +146,6 @@ // CHECK-NEXT: public struct CopyTrackedDerivedClass { // CHECK-NEXT: public init(_ x: Int32) -// CHECK-NEXT: @available(*, deprecated, message: "This zero-initializes the backing memory of the struct, which is unsafe for some C++ structs. Consider adding an explicit default initializer for this C++ struct.") // CHECK-NEXT: @_transparent public init() // CHECK-NEXT: @discardableResult // CHECK-NEXT: public func getDerivedX() -> Int32 @@ -167,7 +165,6 @@ // CHECK-NEXT: public struct CopyTrackedDerivedDerivedClass { // CHECK-NEXT: public init(_ x: Int32) -// CHECK-NEXT: @available(*, deprecated, message: "This zero-initializes the backing memory of the struct, which is unsafe for some C++ structs. Consider adding an explicit default initializer for this C++ struct.") // CHECK-NEXT: @_transparent public init() // CHECK-NEXT: @discardableResult // CHECK-NEXT: public func getY() -> Int32 diff --git a/test/Interop/Cxx/objc-correctness/pthread_mutexattr_t.swift b/test/Interop/Cxx/objc-correctness/pthread_mutexattr_t.swift index d110ef3e9e002..5f100989f5443 100644 --- a/test/Interop/Cxx/objc-correctness/pthread_mutexattr_t.swift +++ b/test/Interop/Cxx/objc-correctness/pthread_mutexattr_t.swift @@ -3,4 +3,4 @@ import Darwin -_ = pthread_mutexattr_t() // expected-warning {{'init()' is deprecated: This zero-initializes the backing memory of the struct}} +_ = pthread_mutexattr_t() diff --git a/test/Interop/Cxx/templates/enable-if-module-interface.swift b/test/Interop/Cxx/templates/enable-if-module-interface.swift index e45b90305bbfd..751c840f3c0af 100644 --- a/test/Interop/Cxx/templates/enable-if-module-interface.swift +++ b/test/Interop/Cxx/templates/enable-if-module-interface.swift @@ -3,7 +3,6 @@ // The `init` constructor template is not yet supported in Swift. // CHECK: struct HasConstructorWithEnableIf { -// CHECK-NEXT: @available(*, deprecated, message: "This zero-initializes the backing memory of the struct, which is unsafe for some C++ structs. Consider adding an explicit default initializer for this C++ struct.") // CHECK-NEXT: init() // CHECK-NEXT:}