Skip to content

Commit 8fce176

Browse files
authored
Merge pull request swiftlang#78786 from swiftlang/egorzhdan/6.1-enum-resilience
🍒[cxx-interop] Assume that plain-C enums are resilient
2 parents cfb9eda + fd9c564 commit 8fce176

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,8 @@ bool isFragileClangDecl(const clang::Decl *decl) {
18871887
return isFragileClangType(pd->getType());
18881888
if (auto *typedefDecl = dyn_cast<clang::TypedefNameDecl>(decl))
18891889
return isFragileClangType(typedefDecl->getUnderlyingType());
1890+
if (auto *enumDecl = dyn_cast<clang::EnumDecl>(decl))
1891+
return enumDecl->isScoped();
18901892
if (auto *rd = dyn_cast<clang::RecordDecl>(decl)) {
18911893
auto cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(rd);
18921894
if (!cxxRecordDecl)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
struct MyCStruct {
22
int x;
33
};
4+
5+
enum MyCEnum {
6+
MCE_One, MCE_Two
7+
};
8+
9+
enum MyCFixedEnum : unsigned {
10+
MCFE_One, MCFE_Two
11+
};

test/Interop/Cxx/library-evolution/allow-c-in-cxx-mode-in-evolving-libraries.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public:
1717
void method() const;
1818
};
1919

20+
enum CEnum {
21+
a, b
22+
};
23+
24+
enum class CxxEnum {
25+
aa, bb
26+
};
27+
2028
#if defined(__cplusplus)
2129
extern "C" {
2230
#endif
@@ -36,6 +44,12 @@ import CxxModule
3644
public func useCStruct(_ x: CStruct) {
3745
}
3846

47+
public func useCEnum(_ x: CEnum) {
48+
}
49+
50+
public func useCxxEnum(_ x: CxxEnum) { // expected-error {{cannot use enum 'CxxEnum' here; C++ types from imported module 'CxxModule' do not support library evolution}}
51+
}
52+
3953
// expected-error@+1 {{cannot use struct 'CxxStruct' here; C++ types from imported module 'CxxModule' do not support library evolution}}
4054
public func usesCxxStruct(_ x: CxxStruct) {
4155
}

test/Interop/Cxx/library-evolution/allow-c-in-cxx-mode-in-interfaces.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@ extension MyCStruct {
3232
}
3333
}
3434

35+
public func getMyCEnum() -> MyCEnum {
36+
return MCE_One
37+
}
38+
39+
public func getMyCFixedEnum() -> MyCFixedEnum {
40+
return MCFE_One
41+
}
42+
3543
//--- main.swift
3644

3745
import UsesCLibrary
3846

3947
let _ = getMyCStruct()
4048
let _ = getMyCStruct().y
4149
let _ = getMyCStruct().anotherInstanceOfSelf
50+
let _ = getMyCEnum()
51+
let _ = getMyCFixedEnum()

0 commit comments

Comments
 (0)