Skip to content

Commit 16cefca

Browse files
authored
Merge pull request #80197 from swiftlang/gaborh/mutating-class-func
[cxx-interop] Do not create mutating properties for classes
2 parents 689586f + 51193fa commit 16cefca

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ static AccessorDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
129129
params, voidTy, importedDecl, clangNode);
130130
setterDecl->setIsObjC(false);
131131
setterDecl->setIsDynamic(false);
132-
setterDecl->setSelfAccessKind(SelfAccessKind::Mutating);
132+
if (!isa<ClassDecl>(importedDecl))
133+
setterDecl->setSelfAccessKind(SelfAccessKind::Mutating);
133134
setterDecl->setAccess(importedFieldDecl->getFormalAccess());
134135

135136
return setterDecl;

test/Interop/Cxx/class/inline-function-codegen/Inputs/method-calls-function.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,18 @@ struct Incrementor {
99

1010
inline int callMethod(int value) { return Incrementor().callIncrement(value); }
1111

12+
class __attribute__((swift_attr("import_reference")))
13+
__attribute__((swift_attr("retain:immortal")))
14+
__attribute__((swift_attr("release:immortal")))
15+
__attribute__((swift_attr("unsafe"))) Cell {
16+
public:
17+
bool is_marked() const { return m_marked; }
18+
void set_marked(bool b) { m_marked = b; }
19+
20+
private:
21+
bool m_marked : 1 {false};
22+
};
23+
24+
inline Cell *_Nonnull createCell() { return new Cell{}; }
25+
1226
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_FUNCTION_H

test/Interop/Cxx/class/inline-function-codegen/method-calls-function-execution.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -cxx-interoperability-mode=default -Xcc -std=c++20 -Xfrontend -disable-availability-checking)
22
//
33
// REQUIRES: executable_test
44

@@ -11,4 +11,11 @@ MembersTestSuite.test("method calls function") {
1111
expectEqual(42, callMethod(41))
1212
}
1313

14+
func doSomethingWith(_ s: Cell) { s.set_marked(true) }
15+
16+
MembersTestSuite.test("method sets bitfield") {
17+
let s = createCell()
18+
doSomethingWith(s)
19+
}
20+
1421
runAllTests()

0 commit comments

Comments
 (0)