diff options
-rw-r--r-- | llvm/include/llvm/Support/TrailingObjects.h | 7 | ||||
-rw-r--r-- | llvm/unittests/Support/TrailingObjectsTest.cpp | 21 |
2 files changed, 28 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/TrailingObjects.h b/llvm/include/llvm/Support/TrailingObjects.h index 4d355724149..cb5a52b0d86 100644 --- a/llvm/include/llvm/Support/TrailingObjects.h +++ b/llvm/include/llvm/Support/TrailingObjects.h @@ -294,7 +294,14 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl< 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 diff --git a/llvm/unittests/Support/TrailingObjectsTest.cpp b/llvm/unittests/Support/TrailingObjectsTest.cpp index cb5c47d1b25..23acc54d237 100644 --- a/llvm/unittests/Support/TrailingObjectsTest.cpp +++ b/llvm/unittests/Support/TrailingObjectsTest.cpp @@ -236,3 +236,24 @@ TEST(TrailingObjects, Realignment) { 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 Class5Tmpl : private llvm::TrailingObjects<Derived, float, int> { + using TrailingObjects = typename llvm::TrailingObjects<Derived, float>; + friend TrailingObjects; + + size_t numTrailingObjects( + typename TrailingObjects::template OverloadToken<float>) const { + return 1; + } + + size_t numTrailingObjects( + typename TrailingObjects::template OverloadToken<int>) const { + return 2; + } +}; + +class Class5 : public Class5Tmpl<Class5> {}; |