<div dir="ltr">I'm trying to port Swift to MSVC, and have pretty much got there, apart from one irritating MSVC bug.<div><br></div><div>Consider the following code:</div><div><br></div><div><div>#include "llvm/Support/TrailingObjects.h"</div><div><br></div><div>class SourceLoc {};</div><div>class Identifier {};</div><div><br></div><div>template<typename Derived></div><div>class TrailingCallArguments</div><div>  : private llvm::TrailingObjects<Derived, SourceLoc, Identifier> {</div><div>  friend TrailingObjects;</div><div><br></div><div>  size_t numTrailingObjects(</div><div>    typename TrailingObjects::template OverloadToken<SourceLoc>) const {</div><div>    return 1;</div><div>  }</div><div><br></div><div>  size_t numTrailingObjects(</div><div>    typename TrailingObjects::template OverloadToken<Identifier>) const {</div><div>    return 2;</div><div>  }</div><div>};</div><div><br></div><div>int main() {</div><div>  TrailingCallArguments<int>();</div><div><br></div><div>  return 0;</div><div>}</div></div><div><br></div><div>Clang/GCC compile this fine. MSVC doesn't (sorry for the long dump of text here):</div><div><br></div><div><div>1>consoleapplication1.cpp(13): error C2751: 'llvm::TrailingObjects<BaseTy,TrailingTys...>::operator OverloadToken': the name of a function parameter cannot be qualified</div><div>1>  consoleapplication1.cpp(21): note: see reference to class template instantiation 'TrailingCallArguments<Derived>' being compiled</div><div>1>consoleapplication1.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int</div><div>1>consoleapplication1.cpp(18): error C2751: 'llvm::TrailingObjects<BaseTy,TrailingTys...>::operator OverloadToken': the name of a function parameter cannot be qualified</div><div>1>consoleapplication1.cpp(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int</div><div>1>consoleapplication1.cpp(18): error C2535: 'size_t TrailingCallArguments<Derived>::numTrailingObjects(int) const': member function already defined or declared</div><div>1>  consoleapplication1.cpp(12): note: see declaration of 'TrailingCallArguments<Derived>::numTrailingObjects'</div><div>1>consoleapplication1.cpp(13): error C2248: 'llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<NextTy>': cannot access inaccessible struct declared in class 'llvm::trailing_objects_internal::TrailingObjectsBase'</div><div>1>          with</div><div>1>          [</div><div>1>              NextTy=SourceLoc</div><div>1>          ]</div><div>1>  c:\users\hughb\documents\llvm\source\include\llvm\support\trailingobjects.h(168): note: see declaration of 'llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<NextTy>'</div><div>1>          with</div><div>1>          [</div><div>1>              NextTy=SourceLoc</div><div>1>          ]</div><div>1>  c:\users\hughb\documents\llvm\source\include\llvm\support\trailingobjects.h(81): note: see declaration of 'llvm::trailing_objects_internal::TrailingObjectsBase'</div><div>1>  consoleapplication1.cpp(25): note: see reference to class template instantiation 'TrailingCallArguments<int>' being compiled</div><div>1>consoleapplication1.cpp(18): error C2248: 'llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<NextTy>': cannot access inaccessible struct declared in class 'llvm::trailing_objects_internal::TrailingObjectsBase'</div><div>1>          with</div><div>1>          [</div><div>1>              NextTy=Identifier</div><div>1>          ]</div><div>1>  c:\users\hughb\documents\llvm\source\include\llvm\support\trailingobjects.h(168): note: see declaration of 'llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<NextTy>'</div><div>1>          with</div><div>1>          [</div><div>1>              NextTy=Identifier</div><div>1>          ]</div><div>1>  c:\users\hughb\documents\llvm\source\include\llvm\support\trailingobjects.h(81): note: see declaration of 'llvm::trailing_objects_internal::TrailingObjectsBase'</div></div><div><br></div><div><br></div><div>There's a workaround. It's ugly, and involves modifying LLVM here: <a href="https://github.com/apple/swift-llvm/pull/33">https://github.com/apple/swift-llvm/pull/33</a> and then modifying the typename termplate stuff: <a href="https://github.com/apple/swift/pull/5948/files#diff-323bdb4c6d842e3b3cd3b40e628c9771R669">https://github.com/apple/swift/pull/5948/files#diff-323bdb4c6d842e3b3cd3b40e628c9771R669</a></div><div><br></div><div>This is brittle and ugly. Is there a better work around for this MSVC compiler bug that LLVM folks can suggest, considering your expertise in LLVM!</div><div>The problem goes away if you change the inheritance of TrailingObjects to have a non-generic BaseType</div><div><br></div><div>- Hugh</div><div><br></div></div>