[PATCH] D29181: Make TrailingObjects private inheritance of TrailingObjectsImpl protected
Hugh Bellamy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 26 08:16:54 PST 2017
hughbe created this revision.
There is an MSVC bug, that caused build errors porting the Swift compiler to Windows, involving trailing objects.
Example code is
class Identifier {};
class SourceLoc {};
template<typename Derived>
class TrailingCallArguments
: private llvm::TrailingObjects<Derived, Identifier, SourceLoc> {
using TrailingObjects = typename llvm::TrailingObjects<Derived, Identifier, SourceLoc>;
friend TrailingObjects;
size_t numTrailingObjects(
typename TrailingObjects::template OverloadToken<Identifier>) const {
return 1;
}
size_t numTrailingObjects(
typename TrailingObjects::template OverloadToken<SourceLoc>) const {
return 2;
}
};
> source_file.cpp(180): error C2751: 'llvm::TrailingObjects<BaseTy,TrailingTys...>::operator OverloadToken': the name of a function parameter cannot be qualified
> source_file.cpp(190): note: see reference to class template instantiation 'TrailingCallArguments<Derived>' being compiled
> source_file.cpp(180): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
> source_file.cpp(185): error C2751: 'llvm::TrailingObjects<BaseTy,TrailingTys...>::operator OverloadToken': the name of a function parameter cannot be qualified
> source_file.cpp(185): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
> source_file.cpp(185): error C2535: 'size_t TrailingCallArguments<Derived>::numTrailingObjects(int) const': member function already defined or declared
> source_file.cpp(179): note: see declaration of 'TrailingCallArguments<Derived>::numTrailingObjects'
There is a connect bug here: https://connect.microsoft.com/VisualStudio/feedback/details/3116517
The fix for this MSVC bug (that will likely be unresolved by VS 2017 is to directly refer to
llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<Identifier>
However, this requires us to give `protected` acess to `TrailingObjectsBase`.
I'm creating this revision, because Jordan Rose (Swift engineer at Apple) suggested I discuss this upstream.
You can see discussion with various members of the community here: https://github.com/apple/swift-llvm/pull/33
You can see the suggestion to bring discussion upstream here: https://github.com/apple/swift-llvm/pull/43
You can see the fix here: https://github.com/apple/swift/pull/5948, https://github.com/apple/swift/pull/5948/files#diff-323bdb4c6d842e3b3cd3b40e628c9771R669
Let me know what you think - it's brittle, but necessary to use TrailingObjects effectively in a generic context with MSVC.
https://reviews.llvm.org/D29181
Files:
include/llvm/Support/TrailingObjects.h
Index: include/llvm/Support/TrailingObjects.h
===================================================================
--- include/llvm/Support/TrailingObjects.h
+++ include/llvm/Support/TrailingObjects.h
@@ -231,12 +231,12 @@
/// See the file comment for details on the usage of the
/// TrailingObjects type.
template <typename BaseTy, typename... TrailingTys>
-class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
- trailing_objects_internal::AlignmentCalcHelper<
- TrailingTys...>::Alignment,
- BaseTy, TrailingObjects<BaseTy, TrailingTys...>,
- BaseTy, TrailingTys...> {
-
+class TrailingObjects
+ : protected trailing_objects_internal::TrailingObjectsImpl<
+ trailing_objects_internal::AlignmentCalcHelper<
+ TrailingTys...>::Alignment,
+ BaseTy, TrailingObjects<BaseTy, TrailingTys...>, BaseTy,
+ TrailingTys...> {
template <int A, typename B, typename T, typename P, typename... M>
friend class trailing_objects_internal::TrailingObjectsImpl;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29181.85910.patch
Type: text/x-patch
Size: 1138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170126/7d5baa9b/attachment.bin>
More information about the llvm-commits
mailing list