Skip to content

Commit 4def042

Browse files
authored
Merge pull request #7890 from hughbe/msvc-workaround
2 parents b661af1 + fdf2282 commit 4def042

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

include/swift/AST/Expr.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/AST/TypeAlignments.h"
2626
#include "swift/AST/TypeLoc.h"
2727
#include "swift/AST/Availability.h"
28-
#include "swift/Basic/Compiler.h"
2928
#include "llvm/Support/TrailingObjects.h"
3029

3130
namespace llvm {
@@ -659,6 +658,14 @@ class alignas(8) Expr {
659658
template<typename Derived>
660659
class TrailingCallArguments
661660
: private llvm::TrailingObjects<Derived, Identifier, SourceLoc> {
661+
// We need to friend TrailingObjects twice here to work around an MSVC bug.
662+
// If we have two functions of the same name with the parameter
663+
// typename TrailingObjectsIdentifier::template OverloadToken<T> where T is
664+
// different for each function, then MSVC reports a "member function already
665+
// defined or declared" error, which is incorrect.
666+
using TrailingObjectsIdentifier = llvm::TrailingObjects<Derived, Identifier>;
667+
friend TrailingObjectsIdentifier;
668+
662669
using TrailingObjects = llvm::TrailingObjects<Derived, Identifier, SourceLoc>;
663670
friend TrailingObjects;
664671

@@ -671,12 +678,14 @@ class TrailingCallArguments
671678
}
672679

673680
size_t numTrailingObjects(
674-
SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN(Identifier)) const {
681+
typename TrailingObjectsIdentifier::template OverloadToken<Identifier>)
682+
const {
675683
return asDerived().getNumArguments();
676684
}
677685

678686
size_t numTrailingObjects(
679-
SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN(SourceLoc)) const {
687+
typename TrailingObjectsIdentifier::template OverloadToken<SourceLoc>)
688+
const {
680689
return asDerived().hasArgumentLabelLocs() ? asDerived().getNumArguments()
681690
: 0;
682691
}

include/swift/Basic/Compiler.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,8 @@
2424
// https://connect.microsoft.com/VisualStudio/feedback/details/3116505
2525
#define SWIFT_DELETE_OPERATOR_DELETED \
2626
{ llvm_unreachable("Delete operator should not be called."); }
27-
28-
// Work around MSVC bug: can't infer llvm::trailing_objects_internal,
29-
// even though we granted friend access to it.
30-
// https://connect.microsoft.com/VisualStudio/feedback/details/3116517
31-
#define SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN(TokenType) \
32-
llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<TokenType>
3327
#else
3428
#define SWIFT_DELETE_OPERATOR_DELETED = delete;
35-
36-
#define SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN(TokenType) \
37-
typename TrailingObjects::template OverloadToken<TokenType>
3829
#endif
3930

4031
#endif // SWIFT_BASIC_COMPILER_H

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ class UnaryInstructionWithTypeDependentOperandsBase :
461461
}
462462
}
463463

464-
size_t
465-
numTrailingObjects(SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN(Operand)) const {
464+
size_t numTrailingObjects(
465+
typename TrailingObjects::template OverloadToken<Operand>) const {
466466
return NumOperands;
467467
}
468468

@@ -2300,8 +2300,8 @@ class BindMemoryInst final :
23002300
SILType getBoundType() const { return BoundType ; }
23012301

23022302
// Implement llvm::TrailingObjects.
2303-
size_t
2304-
numTrailingObjects(SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN(Operand)) const {
2303+
size_t numTrailingObjects(
2304+
typename TrailingObjects::template OverloadToken<Operand>) const {
23052305
return NumOperands;
23062306
}
23072307

0 commit comments

Comments
 (0)