[cxx-interop] Fix assert failure exporting C++ types to Obj-C

This is not supported, of course. But now, instead of an assertion
failure we properly mark the declaration as unavailable.

Fixes #78190.

rdar://141492654
This commit is contained in:
Gabor Horvath
2024-12-16 16:57:30 +00:00
parent 0bbaa3519b
commit e340773dcb
4 changed files with 22 additions and 1 deletions

View File

@@ -918,7 +918,7 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
interopContext, CFunctionSignatureTypePrinterModifierDelegate(),
emittedModule, declPrinter);
auto s = typePrinter.visit(ty, optionalKind, param.isInOut());
assert(!s.isUnsupported());
resultingRepresentation.merge(s);
};
signature.visitParameterList(
[&](const LoweredFunctionSignature::IndirectResultValue

View File

@@ -0,0 +1,5 @@
#pragma once
struct Foo {
void *foo;
};

View File

@@ -0,0 +1,5 @@
module CxxModule [system] {
header "cxxmodule.h"
requires cplusplus
export *
}

View File

@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck %s -module-name UseCxxModule -emit-objc-header -emit-objc-header-path %t/UseCxxTy.h -I %t -I %S/Inputs -clang-header-expose-decls=all-public -cxx-interoperability-mode=default
// RUN: %FileCheck %s < %t/UseCxxTy.h
import CxxModule
public func bar(x: Foo, y: UnsafeMutablePointer<UnsafeMutableRawPointer?>) {}
// CHECK: // Unavailable in C++: Swift global function 'bar(x:y:)'.
// TODO: the message above is not correct, this is actually unavailable in Obj-C.