Skip to content

Commit 4a77ae8

Browse files
committed
[cxx-interop] Fix incorrect diagnostic for non-imported functions
If a C++ function cannot be imported into Swift, we try to emit a diagnostic that explains why. This diagnostic wasn't always correct: for functions that return a C++ struct, we emitted a note saying "function uses foreign reference type in a return type which breaks 'swift_shared_reference' contract" even if the return type is a trivial struct without any attributes. This was emitted unless there was another diagnostic that we also provided for the same function.
1 parent 49dbf15 commit 4a77ae8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,13 +3202,16 @@ namespace {
32023202

32033203
if (auto recordType = dyn_cast<clang::RecordType>(
32043204
decl->getReturnType().getCanonicalType())) {
3205-
Impl.addImportDiagnostic(
3206-
decl, Diagnostic(diag::reference_passed_by_value,
3207-
Impl.SwiftContext.AllocateCopy(
3208-
recordType->getDecl()->getNameAsString()),
3209-
"the return"),
3210-
decl->getLocation());
3211-
return recordHasReferenceSemantics(recordType->getDecl());
3205+
if (recordHasReferenceSemantics(recordType->getDecl())) {
3206+
Impl.addImportDiagnostic(
3207+
decl,
3208+
Diagnostic(diag::reference_passed_by_value,
3209+
Impl.SwiftContext.AllocateCopy(
3210+
recordType->getDecl()->getNameAsString()),
3211+
"the return"),
3212+
decl->getLocation());
3213+
return true;
3214+
}
32123215
}
32133216

32143217
return false;

0 commit comments

Comments
 (0)