Skip to content

Commit 099eade

Browse files
committed
[cxx-interop] Allow some C++ fields in public Swift interfaces
This is a follow-up to 8859b62. This resolves compiler errors when trying to rebuild System.swiftmodule from its textual interface with Xcode 16.1. rdar://140203932 rdar://141124318 (cherry picked from commit e67f2b7)
1 parent 7b226db commit 099eade

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,8 @@ bool isFragileClangType(clang::QualType type) {
18441844
// Pointers to non-fragile types are non-fragile.
18451845
if (underlyingTypePtr->isPointerType())
18461846
return isFragileClangType(underlyingTypePtr->getPointeeType());
1847+
if (auto tagDecl = underlyingTypePtr->getAsTagDecl())
1848+
return isFragileClangDecl(tagDecl);
18471849
return true;
18481850
}
18491851

@@ -1892,6 +1894,11 @@ bool isFragileClangDecl(const clang::Decl *decl) {
18921894
return !cxxRecordDecl->isCLike() &&
18931895
!cxxRecordDecl->getDeclContext()->isExternCContext();
18941896
}
1897+
if (auto *varDecl = dyn_cast<clang::VarDecl>(decl))
1898+
return isFragileClangType(varDecl->getType());
1899+
if (auto *fieldDecl = dyn_cast<clang::FieldDecl>(decl))
1900+
return isFragileClangType(fieldDecl->getType()) ||
1901+
isFragileClangDecl(fieldDecl->getParent());
18951902
return true;
18961903
}
18971904

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,24 @@ public func getMyCStruct() -> MyCStruct {
1818
return MyCStruct()
1919
}
2020

21+
extension MyCStruct {
22+
@inlinable public var y: CInt {
23+
get {
24+
return self.x
25+
}
26+
}
27+
28+
@inlinable public var anotherInstanceOfSelf: MyCStruct {
29+
get {
30+
return MyCStruct(x: self.x + 1)
31+
}
32+
}
33+
}
34+
2135
//--- main.swift
2236

2337
import UsesCLibrary
2438

2539
let _ = getMyCStruct()
40+
let _ = getMyCStruct().y
41+
let _ = getMyCStruct().anotherInstanceOfSelf

0 commit comments

Comments
 (0)