Skip to content

Commit c0b7962

Browse files
authored
Merge pull request #6837 from hughbe/delet-this
Introduce and use SWIFT_DELETE_OPERATOR_DELETED
2 parents 6d5e482 + 201ad5d commit c0b7962

18 files changed

+44
-59
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class AnyFunctionRef {
152152
}
153153

154154
// Disable "only for use within the debugger" warning.
155-
#if COMPILER_IS_MSVC
155+
#if SWIFT_COMPILER_IS_MSVC
156156
#pragma warning(push)
157157
#pragma warning(disable: 4996)
158158
#endif
@@ -177,7 +177,7 @@ class AnyFunctionRef {
177177
llvm_unreachable("unexpected AnyFunctionRef representation");
178178
}
179179
};
180-
#if COMPILER_IS_MSVC
180+
#if SWIFT_COMPILER_IS_MSVC
181181
#pragma warning(pop)
182182
#endif
183183

include/swift/AST/Decl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "swift/AST/LazyResolver.h"
2929
#include "swift/AST/TypeAlignments.h"
3030
#include "swift/AST/Witness.h"
31+
#include "swift/Basic/Compiler.h"
3132
#include "swift/Basic/OptionalEnum.h"
3233
#include "swift/Basic/Range.h"
3334
#include "llvm/ADT/DenseMap.h"
@@ -864,11 +865,7 @@ class alignas(1 << DeclAlignInBits) Decl {
864865

865866
// Make vanilla new/delete illegal for Decls.
866867
void *operator new(size_t Bytes) = delete;
867-
868-
// Work around MSVC error: attempting to reference a deleted function.
869-
#if !defined(_MSC_VER) || defined(__clang__)
870-
void operator delete(void *Data) = delete;
871-
#endif
868+
void operator delete(void *Data) SWIFT_DELETE_OPERATOR_DELETED;
872869

873870
// Only allow allocation of Decls using the allocator in ASTContext
874871
// or by doing a placement new.

include/swift/AST/GenericEnvironment.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include "swift/AST/SubstitutionMap.h"
2121
#include "swift/AST/GenericParamKey.h"
2222
#include "swift/AST/GenericSignature.h"
23+
#include "swift/Basic/Compiler.h"
2324
#include "llvm/ADT/ArrayRef.h"
25+
#include "llvm/Support/ErrorHandling.h"
2426
#include "llvm/Support/TrailingObjects.h"
2527
#include <utility>
2628

@@ -183,9 +185,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
183185

184186
/// Make vanilla new/delete illegal.
185187
void *operator new(size_t Bytes) = delete;
186-
#if !defined(_MSC_VER) || defined(__clang__)
187-
void operator delete(void *Data) = delete;
188-
#endif
188+
void operator delete(void *Data) SWIFT_DELETE_OPERATOR_DELETED;
189189

190190
/// Only allow placement new.
191191
void *operator new(size_t Bytes, void *Mem) {

include/swift/AST/Module.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/LookupKinds.h"
2424
#include "swift/AST/RawComment.h"
2525
#include "swift/AST/Type.h"
26+
#include "swift/Basic/Compiler.h"
2627
#include "swift/Basic/OptionSet.h"
2728
#include "swift/Basic/SourceLoc.h"
2829
#include "swift/Basic/STLExtras.h"
@@ -506,11 +507,7 @@ class ModuleDecl : public TypeDecl, public DeclContext {
506507
private:
507508
// Make placement new and vanilla new/delete illegal for Modules.
508509
void *operator new(size_t Bytes) throw() = delete;
509-
510-
// Work around MSVC error: attempting to reference a deleted function.
511-
#if !defined(_MSC_VER) && !defined(__clang__)
512-
void operator delete(void *Data) throw() = delete;
513-
#endif
510+
void operator delete(void *Data) throw() SWIFT_DELETE_OPERATOR_DELETED;
514511
void *operator new(size_t Bytes, void *Mem) throw() = delete;
515512
public:
516513
// Only allow allocation of Modules using the allocator in ASTContext

include/swift/AST/ProtocolConformance.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/Types.h"
2525
#include "swift/AST/TypeAlignments.h"
2626
#include "swift/AST/Witness.h"
27+
#include "swift/Basic/Compiler.h"
2728
#include "llvm/ADT/ArrayRef.h"
2829
#include "llvm/ADT/DenseMap.h"
2930
#include "llvm/ADT/FoldingSet.h"
@@ -265,11 +266,7 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
265266

266267
// Make vanilla new/delete illegal for protocol conformances.
267268
void *operator new(size_t bytes) = delete;
268-
269-
// Work around MSVC error: attempting to reference a deleted function.
270-
#if !defined(_MSC_VER) || defined(__clang__)
271-
void operator delete(void *data) = delete;
272-
#endif
269+
void operator delete(void *data) SWIFT_DELETE_OPERATOR_DELETED;
273270

274271
// Only allow allocation of protocol conformances using the allocator in
275272
// ASTContext or by doing a placement new.

include/swift/AST/TypeRepr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ enum class TypeReprKind : uint8_t {
4242

4343
/// \brief Representation of a type as written in source.
4444
class alignas(8) TypeRepr {
45-
// Fix MSVC error: attempting to reference a deleted function.
46-
#if !defined(_MSC_VER) || defined(__clang__)
4745
TypeRepr(const TypeRepr&) = delete;
48-
#endif
4946
void operator=(const TypeRepr&) = delete;
5047

5148
class TypeReprBitfields {

include/swift/Basic/Compiler.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@
1414
#define SWIFT_BASIC_COMPILER_H
1515

1616
#if defined(_MSC_VER) && !defined(__clang__)
17-
#define COMPILER_IS_MSVC 1
17+
#define SWIFT_COMPILER_IS_MSVC 1
1818
#else
19-
#define COMPILER_IS_MSVC 0
19+
#define SWIFT_COMPILER_IS_MSVC 0
20+
#endif
21+
22+
#if SWIFT_COMPILER_IS_MSVC
23+
// Work around MSVC bug: attempting to reference a deleted function
24+
// https://connect.microsoft.com/VisualStudio/feedback/details/3116505
25+
#define SWIFT_DELETE_OPERATOR_DELETED \
26+
{ llvm_unreachable("Delete operator should not be called."); }
27+
#else
28+
#define SWIFT_DELETE_OPERATOR_DELETED = delete;
2029
#endif
2130

2231
#endif // SWIFT_BASIC_COMPILER_H

include/swift/Basic/EncodedSequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class EncodedSequence : public EncodedSequenceBase {
340340
template <class ValueType> class Map {
341341
// Hack: MSVC isn't able to resolve the InlineKeyCapacity part of the
342342
// template of PrefixMap, so we have to split it up and pass it manually.
343-
#if COMPILER_IS_MSVC
343+
#if SWIFT_COMPILER_IS_MSVC
344344
static const size_t Size = (sizeof(void*) - 1) / sizeof(Chunk);
345345
static const size_t ActualSize = max<size_t>(Size, 1);
346346

include/swift/Basic/type_traits.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace swift {
3030
/// is not intended to be specialized.
3131
template<typename T>
3232
struct IsTriviallyCopyable {
33-
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
33+
#if _LIBCPP_VERSION || SWIFT_COMPILER_IS_MSVC
3434
// libc++ and MSVC implement is_trivially_copyable.
3535
static const bool value = std::is_trivially_copyable<T>::value;
3636
#elif __has_feature(is_trivially_copyable)
@@ -42,7 +42,7 @@ struct IsTriviallyCopyable {
4242

4343
template<typename T>
4444
struct IsTriviallyConstructible {
45-
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
45+
#if _LIBCPP_VERSION || SWIFT_COMPILER_IS_MSVC
4646
// libc++ and MSVC implement is_trivially_constructible.
4747
static const bool value = std::is_trivially_constructible<T>::value;
4848
#elif __has_feature(has_trivial_constructor)
@@ -54,7 +54,7 @@ struct IsTriviallyConstructible {
5454

5555
template<typename T>
5656
struct IsTriviallyDestructible {
57-
#if _LIBCPP_VERSION || COMPILER_IS_MSVC
57+
#if _LIBCPP_VERSION || SWIFT_COMPILER_IS_MSVC
5858
// libc++ and MSVC implement is_trivially_destructible.
5959
static const bool value = std::is_trivially_destructible<T>::value;
6060
#elif __has_feature(has_trivial_destructor)

include/swift/SIL/SILAllocated.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define SWIFT_SIL_SILALLOCATED_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/Compiler.h"
18+
#include "llvm/Support/ErrorHandling.h"
1719
#include <stddef.h>
1820

1921
namespace swift {
@@ -28,11 +30,8 @@ class SILAllocated {
2830
void *operator new(size_t) = delete;
2931
void *operator new[](size_t) = delete;
3032

31-
// Work around MSVC error: attempting to reference a deleted function.
32-
#if !defined(_MSC_VER) || defined(__clang__)
3333
/// Disable non-placement delete.
34-
void operator delete(void *) = delete;
35-
#endif
34+
void operator delete(void *) SWIFT_DELETE_OPERATOR_DELETED;
3635
void operator delete[](void *) = delete;
3736

3837
/// Custom version of 'new' that uses the SILModule's BumpPtrAllocator with

include/swift/SIL/SILArgument.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SIL_SILARGUMENT_H
1414
#define SWIFT_SIL_SILARGUMENT_H
1515

16+
#include "swift/Basic/Compiler.h"
1617
#include "swift/SIL/SILArgumentConvention.h"
1718
#include "swift/SIL/SILFunction.h"
1819
#include "swift/SIL/SILValue.h"
@@ -36,11 +37,7 @@ SILFunctionType::getSILArgumentConvention(unsigned index) const {
3637

3738
class SILArgument : public ValueBase {
3839
void operator=(const SILArgument &) = delete;
39-
40-
// Work around MSVC error: attempting to reference a deleted function.
41-
#if !defined(_MSC_VER) || defined(__clang__)
42-
void operator delete(void *Ptr, size_t) = delete;
43-
#endif
40+
void operator delete(void *Ptr, size_t) SWIFT_DELETE_OPERATOR_DELETED
4441

4542
SILBasicBlock *ParentBB;
4643
const ValueDecl *Decl;

include/swift/SIL/SILBasicBlock.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_SIL_BASICBLOCK_H
1818
#define SWIFT_SIL_BASICBLOCK_H
1919

20+
#include "swift/Basic/Compiler.h"
2021
#include "swift/Basic/Range.h"
2122
#include "swift/Basic/TransformArrayRef.h"
2223
#include "swift/SIL/SILInstruction.h"
@@ -53,10 +54,7 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
5354
SILBasicBlock() : Parent(nullptr) {}
5455
void operator=(const SILBasicBlock &) = delete;
5556

56-
// Work around MSVC error: attempting to reference a deleted function.
57-
#if !defined(_MSC_VER) || defined(__clang__)
58-
void operator delete(void *Ptr, size_t) = delete;
59-
#endif
57+
void operator delete(void *Ptr, size_t) SWIFT_DELETE_OPERATOR_DELETED
6058

6159
SILBasicBlock(SILFunction *F, SILBasicBlock *afterBB = nullptr);
6260

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "swift/AST/Builtins.h"
2121
#include "swift/AST/ProtocolConformanceRef.h"
22+
#include "swift/Basic/Compiler.h"
2223
#include "swift/SIL/Consumption.h"
2324
#include "swift/SIL/SILAllocated.h"
2425
#include "swift/SIL/SILArgumentConvention.h"
@@ -80,11 +81,7 @@ class SILInstruction : public ValueBase,public llvm::ilist_node<SILInstruction>{
8081

8182
SILInstruction() = delete;
8283
void operator=(const SILInstruction &) = delete;
83-
84-
// Work around MSVC error: attempting to reference a deleted function.
85-
#if !defined(_MSC_VER) || defined(__clang__)
86-
void operator delete(void *Ptr, size_t) = delete;
87-
#endif
84+
void operator delete(void *Ptr, size_t) SWIFT_DELETE_OPERATOR_DELETED
8885

8986
/// Check any special state of instructions that are not represented in the
9087
/// instructions operands/type.

include/swift/SIL/SILOpenedArchetypesTracker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace swift {
2323

2424
// Disable MSVC warning: multiple copy constructors specified.
2525
// TODO: silence this warning.
26-
#if COMPILER_IS_MSVC
26+
#if SWIFT_COMPILER_IS_MSVC
2727
#pragma warning(push)
2828
#pragma warning(disable: 4521)
2929
#endif
@@ -136,7 +136,7 @@ class SILOpenedArchetypesTracker : public DeleteNotificationHandler {
136136
OpenedArchetypeDefsMap LocalOpenedArchetypeDefs;
137137
};
138138

139-
#if COMPILER_IS_MSVC
139+
#if SWIFT_COMPILER_IS_MSVC
140140
#pragma warning(pop)
141141
#endif
142142

include/swift/SIL/SILUndef.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@
1313
#ifndef SWIFT_SIL_UNDEF_H
1414
#define SWIFT_SIL_UNDEF_H
1515

16+
#include "swift/Basic/Compiler.h"
1617
#include "swift/SIL/SILValue.h"
1718

1819
namespace swift {
1920
class SILModule;
2021

2122
class SILUndef : public ValueBase {
2223
void operator=(const SILArgument &) = delete;
23-
24-
// Work around MSVC error: attempting to reference a deleted function.
25-
#if !defined(_MSC_VER) || defined(__clang__)
26-
void operator delete(void *Ptr, size_t) = delete;
27-
#endif
24+
void operator delete(void *Ptr, size_t) SWIFT_DELETE_OPERATOR_DELETED
2825

2926
SILUndef(SILType Ty) : ValueBase(ValueKind::SILUndef, Ty) {}
3027
public:

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ struct ASTContext::Implementation {
278278
conformance.~SpecializedProtocolConformance();
279279
// Work around MSVC warning: local variable is initialized but
280280
// not referenced.
281-
#if COMPILER_IS_MSVC
281+
#if SWIFT_COMPILER_IS_MSVC
282282
#pragma warning (disable: 4189)
283283
#endif
284284
for (auto &conformance : InheritedConformances)
285285
conformance.~InheritedProtocolConformance();
286-
#if COMPILER_IS_MSVC
286+
#if SWIFT_COMPILER_IS_MSVC
287287
#pragma warning (default: 4189)
288288
#endif
289289

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ namespace {
843843
template <typename T>
844844
struct OperatorLookup {
845845
// TODO: this assertion fails in MSVC, but not clang-cl.
846-
#if !COMPILER_IS_MSVC
846+
#if !SWIFT_COMPILER_IS_MSVC
847847
static_assert(static_cast<T*>(nullptr), "Only usable with operators");
848848
#endif
849849
};

lib/Sema/Constraint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,12 @@ void Constraint::dump(ConstraintSystem *CS) const {
334334
llvm::SaveAndRestore<bool> X(CS->getASTContext().LangOpts.
335335
DebugConstraintSolver, true);
336336
// Disable MSVC warning: only for use within the debugger.
337-
#if COMPILER_IS_MSVC
337+
#if SWIFT_COMPILER_IS_MSVC
338338
#pragma warning(push)
339339
#pragma warning(disable: 4996)
340340
#endif
341341
dump(&CS->getASTContext().SourceMgr);
342-
#if COMPILER_IS_MSVC
342+
#if SWIFT_COMPILER_IS_MSVC
343343
#pragma warning(pop)
344344
#endif
345345
}

0 commit comments

Comments
 (0)