Skip to content

Commit 5c3b4ca

Browse files
committed
[interop][SwiftToCxx] annotate OpaqueStorage with noexcept
1 parent 38387ad commit 5c3b4ca

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/PrintAsClang/PrintSwiftToClangCoreScaffold.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,34 @@ inline void opaqueFree(void * _Nonnull p) {
133133
}
134134

135135
static void printSwiftResilientStorageClass(raw_ostream &os) {
136-
// FIXME: mark noexcept.
137136
auto name = cxx_synthesis::getCxxOpaqueStorageClassName();
138137
static_assert(TargetValueWitnessFlags<uint64_t>::AlignmentMask ==
139138
TargetValueWitnessFlags<uint32_t>::AlignmentMask,
140139
"alignment mask doesn't match");
141140
os << "/// Container for an opaque Swift value, like resilient struct.\n";
142141
os << "class " << name << " {\n";
143142
os << "public:\n";
144-
os << " inline " << name << "() : storage(nullptr) { }\n";
143+
os << " inline " << name << "() noexcept : storage(nullptr) { }\n";
145144
os << " inline " << name
146-
<< "(ValueWitnessTable * _Nonnull vwTable) : storage("
145+
<< "(ValueWitnessTable * _Nonnull vwTable) noexcept : storage("
147146
"reinterpret_cast<char *>(opaqueAlloc(vwTable->size, (vwTable->flags &"
148147
<< TargetValueWitnessFlags<uint64_t>::AlignmentMask << ") + 1))) { }\n";
149148
os << " inline " << name << "(" << name
150-
<< "&& other) : storage(other.storage) { other.storage = nullptr; }\n";
151-
os << " inline " << name << "(const " << name << "&) = delete;\n";
149+
<< "&& other) noexcept : storage(other.storage) { other.storage = "
150+
"nullptr; }\n";
151+
os << " inline " << name << "(const " << name << "&) noexcept = delete;\n";
152152
os << " inline ~" << name
153-
<< "() { if (storage) { opaqueFree(static_cast<char "
153+
<< "() noexcept { if (storage) { opaqueFree(static_cast<char "
154154
"* _Nonnull>(storage)); } }\n";
155155
os << " void operator =(" << name
156-
<< "&& other) { auto temp = storage; storage = other.storage; "
156+
<< "&& other) noexcept { auto temp = storage; storage = other.storage; "
157157
"other.storage = temp; }\n";
158-
os << " void operator =(const " << name << "&) = delete;\n";
159-
os << " inline char * _Nonnull getOpaquePointer() { return static_cast<char "
158+
os << " void operator =(const " << name << "&) noexcept = delete;\n";
159+
os << " inline char * _Nonnull getOpaquePointer() noexcept { return "
160+
"static_cast<char "
160161
"* _Nonnull>(storage); }\n";
161-
os << " inline const char * _Nonnull getOpaquePointer() const { return "
162+
os << " inline const char * _Nonnull getOpaquePointer() const noexcept { "
163+
"return "
162164
"static_cast<char * _Nonnull>(storage); }\n";
163165
os << "private:\n";
164166
os << " char * _Nullable storage;\n";

test/Interop/SwiftToCxx/core/swift-impl-defs-in-cxx.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@
6565
// CHECK-NEXT: /// Container for an opaque Swift value, like resilient struct.
6666
// CHECK-NEXT: class OpaqueStorage {
6767
// CHECK-NEXT: public:
68-
// CHECK-NEXT: inline OpaqueStorage() : storage(nullptr) { }
69-
// CHECK-NEXT: inline OpaqueStorage(ValueWitnessTable * _Nonnull vwTable) : storage(reinterpret_cast<char *>(opaqueAlloc(vwTable->size, (vwTable->flags &255) + 1))) { }
70-
// CHECK-NEXT: inline OpaqueStorage(OpaqueStorage&& other) : storage(other.storage) { other.storage = nullptr; }
71-
// CHECK-NEXT: inline OpaqueStorage(const OpaqueStorage&) = delete;
72-
// CHECK-NEXT: inline ~OpaqueStorage() { if (storage) { opaqueFree(static_cast<char * _Nonnull>(storage)); } }
73-
// CHECK-NEXT: void operator =(OpaqueStorage&& other) { auto temp = storage; storage = other.storage; other.storage = temp; }
74-
// CHECK-NEXT: void operator =(const OpaqueStorage&) = delete;
75-
// CHECK-NEXT: inline char * _Nonnull getOpaquePointer() { return static_cast<char * _Nonnull>(storage); }
76-
// CHECK-NEXT: inline const char * _Nonnull getOpaquePointer() const { return static_cast<char * _Nonnull>(storage); }
68+
// CHECK-NEXT: inline OpaqueStorage() noexcept : storage(nullptr) { }
69+
// CHECK-NEXT: inline OpaqueStorage(ValueWitnessTable * _Nonnull vwTable) noexcept : storage(reinterpret_cast<char *>(opaqueAlloc(vwTable->size, (vwTable->flags &255) + 1))) { }
70+
// CHECK-NEXT: inline OpaqueStorage(OpaqueStorage&& other) noexcept : storage(other.storage) { other.storage = nullptr; }
71+
// CHECK-NEXT: inline OpaqueStorage(const OpaqueStorage&) noexcept = delete;
72+
// CHECK-NEXT: inline ~OpaqueStorage() noexcept { if (storage) { opaqueFree(static_cast<char * _Nonnull>(storage)); } }
73+
// CHECK-NEXT: void operator =(OpaqueStorage&& other) noexcept { auto temp = storage; storage = other.storage; other.storage = temp; }
74+
// CHECK-NEXT: void operator =(const OpaqueStorage&) noexcept = delete;
75+
// CHECK-NEXT: inline char * _Nonnull getOpaquePointer() noexcept { return static_cast<char * _Nonnull>(storage); }
76+
// CHECK-NEXT: inline const char * _Nonnull getOpaquePointer() const noexcept { return static_cast<char * _Nonnull>(storage); }
7777
// CHECK-NEXT: private:
7878
// CHECK-NEXT: char * _Nullable storage;
7979
// CHECK-NEXT: };

0 commit comments

Comments
 (0)