Skip to content

Swift should allow multiple SWIFT_CONFORMS_TO_PROTOCOL attributes on a C++ class #75831

@egorzhdan

Description

@egorzhdan

Description

swift/bridging header defines a SWIFT_CONFORMS_TO_PROTOCOL macro, which expands to __attribute__((swift_attr("conforms_to:MyModule.MyProtocol"))).

This attribute lets the Swift compiler know that the annotated C++ class should be automatically marked as conforming to a Swift protocol with the given name.

Currently the Swift compiler only respects one SWIFT_CONFORMS_TO_PROTOCOL attribute on a single C++ class at a time. This is a limitation, we should support multiple SWIFT_CONFORMS_TO_PROTOCOL attributes on a single class.

Reproduction

Expected behavior

If two or more SWIFT_CONFORMS_TO_PROTOCOL attributes are provided, Swift should conform the C++ type to all of the listed Swift protocols.

Environment

Recent Swift compiler from main

Additional information

This is the part of ClangImporter that handles explicit conformances:

void
addExplicitProtocolConformances(NominalTypeDecl *decl,
const clang::CXXRecordDecl *clangDecl) {

This method would likely need to change as part of the resolution of this issue.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++clang importerArea → compiler: The clang importercompilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesgood first issueGood for newcomersswift 6.2unexpected behaviorBug: Unexpected behavior or incorrect output

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions