[PATCH] D29880: Workaround MSVC bug when using TrailingObjects from a template.

James Y Knight via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 12 20:41:12 PST 2017


jyknight created this revision.

MSVC appears to be getting confused as to whether OverloadToken is
supposed to be public or not.

Reported to microsoft by hughbe:
https://connect.microsoft.com/VisualStudio/feedback/details/3116517


https://reviews.llvm.org/D29880

Files:
  include/llvm/Support/TrailingObjects.h
  unittests/Support/TrailingObjectsTest.cpp


Index: unittests/Support/TrailingObjectsTest.cpp
===================================================================
--- unittests/Support/TrailingObjectsTest.cpp
+++ unittests/Support/TrailingObjectsTest.cpp
@@ -236,3 +236,19 @@
                 reinterpret_cast<char *>(C + 1) + 1, alignof(long))));
 }
 }
+
+// Test the use of TrailingObjects with a template class. This
+// previously failed to compile due to a bug in MSVC's member access
+// control/lookup handling for OverloadToken.
+template<typename Derived>
+class Class5 : private llvm::TrailingObjects<Derived, float> {
+  using TrailingObjects = typename llvm::TrailingObjects<Derived, float>;
+  friend TrailingObjects;
+
+  size_t numTrailingObjects(
+      typename TrailingObjects::template OverloadToken<float>) const {
+    return 1;
+  }
+};
+
+template class Class5<int>; // instantiate to trigger the error
Index: include/llvm/Support/TrailingObjects.h
===================================================================
--- include/llvm/Support/TrailingObjects.h
+++ include/llvm/Support/TrailingObjects.h
@@ -294,7 +294,12 @@
 
 public:
   // Make this (privately inherited) member public.
+#ifndef _MSC_VER
   using ParentType::OverloadToken;
+#else
+  // MSVC bug prevents the above from working, at least up through CL 19.10.24629.
+  template<typename T> using OverloadToken = typename ParentType::template OverloadToken<T>;
+#endif
 
   /// Returns a pointer to the trailing object array of the given type
   /// (which must be one of those specified in the class template). The


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29880.88154.patch
Type: text/x-patch
Size: 1559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170213/456672aa/attachment.bin>


More information about the llvm-commits mailing list