File tree 3 files changed +29
-2
lines changed
3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 133
133
#define SWIFT_COMPUTED_PROPERTY \
134
134
__attribute__ ((swift_attr(" import_computed_property" )))
135
135
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
+
136
143
#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
137
144
138
145
// Empty defines for compilers that don't support `attribute(swift_attr)`.
144
151
#define SWIFT_NAME (_name )
145
152
#define SWIFT_CONFORMS_TO_PROTOCOL (_moduleName_protocolName )
146
153
#define SWIFT_COMPUTED_PROPERTY
154
+ #define SWIFT_MUTATING
147
155
148
156
#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
149
157
Original file line number Diff line number Diff line change 1
1
#ifndef TEST_INTEROP_CXX_CLASS_INPUTS_MUTABLE_MEMBERS_H
2
2
#define TEST_INTEROP_CXX_CLASS_INPUTS_MUTABLE_MEMBERS_H
3
3
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
+
4
13
struct HasPublicMutableMember {
5
14
mutable int a = 0 ;
6
15
7
- int foo () const {
16
+ int foo () const SWIFT_MUTATING {
8
17
a++;
9
18
return a;
10
19
}
@@ -15,7 +24,7 @@ struct HasPrivateMutableMember {
15
24
mutable int a = 0 ;
16
25
17
26
public:
18
- void bar () const { a++; }
27
+ void bar () const SWIFT_MUTATING { a++; }
19
28
};
20
29
21
30
#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