File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 133133#define SWIFT_COMPUTED_PROPERTY \
134134 __attribute__ ((swift_attr(" import_computed_property" )))
135135
136+ // / Specifies that a specific **constant** C++ member function should be imported as
137+ // / `mutating` Swift method. This annotation should be added to constant C++ member functions
138+ // / that mutate `mutable` fields in a C++ object, to let Swift know that this function is still mutating
139+ // / and thus that it should become a `mutating` method in Swift.
140+ #define SWIFT_MUTATING \
141+ __attribute__ ((swift_attr(" mutating" )))
142+
136143#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
137144
138145// Empty defines for compilers that don't support `attribute(swift_attr)`.
144151#define SWIFT_NAME (_name )
145152#define SWIFT_CONFORMS_TO_PROTOCOL (_moduleName_protocolName )
146153#define SWIFT_COMPUTED_PROPERTY
154+ #define SWIFT_MUTATING
147155
148156#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
149157
Original file line number Diff line number Diff line change 11#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_MUTABLE_MEMBERS_H
22#define TEST_INTEROP_CXX_CLASS_INPUTS_MUTABLE_MEMBERS_H
33
4+ #ifdef USE_MUTATING
5+ // Note: in actuality, this will be included
6+ // as <swift/bridging>, but in this test we include
7+ // it directly.
8+ #include " bridging"
9+ #else
10+ #define SWIFT_MUTATING
11+ #endif
12+
413struct HasPublicMutableMember {
514 mutable int a = 0 ;
615
7- int foo () const {
16+ int foo () const SWIFT_MUTATING {
817 a++;
918 return a;
1019 }
@@ -15,7 +24,7 @@ struct HasPrivateMutableMember {
1524 mutable int a = 0 ;
1625
1726public:
18- void bar () const { a++; }
27+ void bar () const SWIFT_MUTATING { a++; }
1928};
2029
2130#endif // TEST_INTEROP_CXX_CLASS_INPUTS_MUTABLE_MEMBERS_H
Original file line number Diff line number Diff line change 1+ // RUN: %target-swift-ide-test -print-module -module-to-print=MutableMembers -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -Xcc -DUSE_MUTATING -I %swift_src_root/lib/ClangImporter | %FileCheck %s
2+
3+ // CHECK: struct HasPublicMutableMember {
4+ // CHECK: mutating func foo() -> Int32
5+ // CHECK: var a: Int32
6+ // CHECK: }
7+
8+ // CHECK: struct HasPrivateMutableMember {
9+ // CHECK: mutating func bar()
10+ // CHECK: }
You can’t perform that action at this time.
0 commit comments