[cxx-interop] plain C++ enums should be importable into Swift #64313
Labels
c++ interop
Feature: Interoperability with C++
c++ to swift
Feature → c++ interop: c++ to swift
compiler
The Swift compiler in itself
enums c++
Feature → c++ interop: c++ enums
feature
A feature request or implementation
Motivation
Currently only C++ "class enums" can be imported into Swift. This is fine for enums that are entirely under the user's control, but in some cases those APIs come from external dependencies or can't be modified for some reason (e.g. API compatibility).
Ideally there would still be a way to import these into Swift without having to write a shim wrapper re-exposing them.
Currently if you have this C++ code:
As far as I know the only way to construct the
first
member of theParent::Child::MyEnum
enum from Swift is to use thekMyEnumFirst
constant.If the enum is changed to a "class enum" then this works fine:
Solution
Ideally it should be possible to construct the
first
member of theParent::Child::MyEnum
enum from Swift just like a class enum would be imported.Alternatives considered
But if that isn't possible for some reason, then ideally the clang importer would generate accessors to all the enum fields in some other way:
Additional context
Thread in Swift Open Source Slack: https://swift-open-source.slack.com/archives/C03FAHQK8F7/p1678459701676699
PRs changing plain enums to enum classes to work around this issue: envoyproxy/envoy#26036 and envoyproxy/envoy#26037
The text was updated successfully, but these errors were encountered: