From 7c05cd7147e4e46d8bd1bd6730a18aca52ae74ec Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Sat, 12 Nov 2016 09:33:16 +0000 Subject: [PATCH] Add workaround for MSVC bug See https://github.com/apple/swift/pull/3759#event-734591467 The problem is that MSVC doesn't recognise the following syntax, reporting multiple errors [here](https://github.com/apple/swift/blob/master/include/swift/AST/Expr.h#L661): ``` size_t numTrailingObjects( typename TrailingObjects::template OverloadToken) const { return asDerived().hasArgumentLabelLocs() ? asDerived().getNumArguments() : 0; } ``` For some reason, MSVC ignores the fact that we gave friend access to `llvm::TrailingObjects` [here](). Note that the Swift source code also has to be modified, as this is not enough. This is the new source code, that fully compiles after this change! ``` // Work around MSVC bug: can't infer llvm::trailing_objects_internal, even though we granted friend access to it size_t numTrailingObjects( #if defined(_MSC_VER) llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken) const { #else typename TrailingObjects::template OverloadToken) const { #endif return asDerived().getNumArguments(); } ``` --- include/llvm/Support/TrailingObjects.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/llvm/Support/TrailingObjects.h b/include/llvm/Support/TrailingObjects.h index 427ae1cb3f6..0f273090804 100644 --- a/include/llvm/Support/TrailingObjects.h +++ b/include/llvm/Support/TrailingObjects.h @@ -257,7 +257,14 @@ class TrailingObjectsImpl /// See the file comment for details on the usage of the /// TrailingObjects type. template + +// Work around MSVC build error: cannot access inaccessible struct declared +// in class'llvm::trailing_objects_internal::TrailingObjectsBase' +#if defined(_MSC_VER) +class TrailingObjects : protected trailing_objects_internal::TrailingObjectsImpl< +#else class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl< +#endif trailing_objects_internal::AlignmentCalcHelper< TrailingTys...>::Alignment, BaseTy, TrailingObjects,