Skip to content

Commit 4dfa638

Browse files
committed
Introduce and use SWIFT_DELETE_OPERATOR_DELETED
1 parent 429ae04 commit 4dfa638

File tree

11 files changed

+29
-44
lines changed

11 files changed

+29
-44
lines changed

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@
1919
#define COMPILER_IS_MSVC 0
2020
#endif
2121

22+
#if 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;
29+
#endif
30+
2231
#endif // SWIFT_BASIC_COMPILER_H

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/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:

0 commit comments

Comments
 (0)