Skip to content

Commit 3848548

Browse files
martinboehmezoecarver
authored andcommitted
Revert "Only import constructors marked noexcept."
This reverts commit 29650d8. As discussed here, we want to import all constructors (whether they are marked `noexcept` or not) as non-throwing initializers; https://forums.swift.org/t/handling-c-exceptions/34823/50
1 parent 7ad2eef commit 3848548

File tree

3 files changed

+3
-15
lines changed

3 files changed

+3
-15
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3893,12 +3893,7 @@ namespace {
38933893

38943894
AbstractFunctionDecl *result = nullptr;
38953895
if (auto *ctordecl = dyn_cast<clang::CXXConstructorDecl>(decl)) {
3896-
// For the time being, we only import `noexcept` constructors.
3897-
// TODO: Import throwing constructors too.
3898-
auto *prototype = decl->getType()->getAs<clang::FunctionProtoType>();
3899-
if (!prototype || !prototype->hasNoexceptExceptionSpec())
3900-
return nullptr;
3901-
3896+
// TODO: Is failable, throws etc. correct?
39023897
DeclName ctorName(Impl.SwiftContext, DeclBaseName::createConstructor(),
39033898
bodyParams);
39043899
result = Impl.createDeclWithClangNode<ConstructorDecl>(

test/CXXInterop/Inputs/cxx_constructors.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct ExplicitDefaultConstructor {
2-
ExplicitDefaultConstructor() noexcept : x(42) {}
2+
ExplicitDefaultConstructor() : x(42) {}
33
int x;
44
};
55

@@ -17,10 +17,6 @@ struct DefaultConstructorDeleted {
1717
};
1818

1919
struct ConstructorWithParam {
20-
ConstructorWithParam(int val) noexcept : x(val) {}
20+
ConstructorWithParam(int val) : x(val) {}
2121
int x;
2222
};
23-
24-
struct PotentiallyThrowingConstructor {
25-
PotentiallyThrowingConstructor() {}
26-
};

test/CXXInterop/cxx-constructors-typecheck.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ let deletedImplicitly = ConstructorWithParam() // expected-error {{missing argum
1111
let deletedExplicitly = DefaultConstructorDeleted() // expected-error {{cannot be constructed because it has no accessible initializers}}
1212

1313
let withArg = ConstructorWithParam(42)
14-
15-
// For the time being, we only import constructors marked `noexcept`.
16-
let potentiallyThrowing = PotentiallyThrowingConstructor() // expected-error {{cannot be constructed because it has no accessible initializers}}

0 commit comments

Comments
 (0)