Skip to content

Commit 8ea7569

Browse files
authored
Merge pull request #76286 from hyp/eng/bodyParamsimport
[cxx-interop] do not rely on bodyParams being always non-null when im…
2 parents 3f916f5 + 86886d9 commit 8ea7569

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,20 +3645,20 @@ namespace {
36453645
}
36463646
}
36473647

3648-
if (name && name.isSimpleName()) {
3649-
assert(importedName.hasCustomName() &&
3650-
"imported function with simple name?");
3651-
// Just fill in empty argument labels.
3652-
name = DeclName(Impl.SwiftContext, name.getBaseName(), bodyParams);
3653-
}
3654-
36553648
if (!bodyParams) {
36563649
Impl.addImportDiagnostic(
36573650
decl, Diagnostic(diag::invoked_func_not_imported, decl),
36583651
decl->getSourceRange().getBegin());
36593652
return nullptr;
36603653
}
36613654

3655+
if (name && name.isSimpleName()) {
3656+
assert(importedName.hasCustomName() &&
3657+
"imported function with simple name?");
3658+
// Just fill in empty argument labels.
3659+
name = DeclName(Impl.SwiftContext, name.getBaseName(), bodyParams);
3660+
}
3661+
36623662
if (name && name.getArgumentNames().size() != bodyParams->size()) {
36633663
// We synthesized additional parameters so rebuild the DeclName.
36643664
name = DeclName(Impl.SwiftContext, name.getBaseName(), bodyParams);

test/Interop/Cxx/operators/Inputs/member-inline.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,23 @@ class HasStaticOperatorCallWithConstOperator {
501501
}
502502
};
503503

504+
505+
// This type is intentionally unimportable,
506+
// to ensure that the function that uses in a parameter
507+
// cannot import its parameter list.
508+
struct UnimportableCxxTypeByDefault {
509+
private:
510+
UnimportableCxxTypeByDefault(const UnimportableCxxTypeByDefault &) = delete;
511+
UnimportableCxxTypeByDefault(UnimportableCxxTypeByDefault &&) = delete;
512+
};
513+
514+
struct HasStaticOperatorCallWithUnimportableCxxType {
515+
// This operator won't be imported.
516+
static int operator()(const UnimportableCxxTypeByDefault &) noexcept {
517+
return 0;
518+
}
519+
};
520+
504521
struct ClassWithOperatorStarAvailable {
505522
int value;
506523

test/Interop/Cxx/operators/member-inline-module-interface.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,7 @@
307307
// CHECK: func callAsFunction(_ x: Int32, _ y: Int32) -> Int32
308308
// CHECK: func callAsFunction(_ x: Int32) -> Int32
309309
// CHECK: }
310+
311+
// CHECK: struct HasStaticOperatorCallWithUnimportableCxxType {
312+
// CHECK-NEXT: init()
313+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)