if (TC.Verify() && TC.isForwardDecl())
ReplaceMap.push_back(Ty.getTypeOrNull(), TC);
Note that TC is of type llvm:DIType and not WeakVH.
What am I missing, as this does not compile under Visual Studio 2012 RC?
Tricky code, DIType (or rather its superclass DIDescriptor) implicitly converts to MDNode* via a operator overload. MDNode is a subclass of Value, and WeakVH is constructible from Value*.
Wouldn't surprise me if MSVC has problems eating that, lots of magic involved here.
The reason it gives is std::pair<_Ty1,_Ty2>' to 'std::pair<_Ty3,_Ty4>, but as you point out there is indeed a conversion operator for DITYPE to WeakVH. Putting the explicit cast to give:
if (T.Verify() && T.isForwardDecl())
ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(), (llvm::MDNode *)T));
and all it well again. This does indeed seem to be a bug in VS, unless there is some C++11 changes that stops implicit conversion under std::pair.
I tracked this issue down and it turns out that Visual Studio is correct and this is a bug in the LLVM code with respect to C++11. (Note: it is valid C++ 2003, it is just that VS 2012 RC is closer to C++11 now, at least in this regard.)
The C++11 specification has change from C++ 2003 and is described in the ISO spec:
"template<class U, class V> pair(const pair<U, V>& p);
Remark: This constructor shall not participate in overload resolution unless const U& is implicitly convertible to first_type and const V& is implicitly convertible to second_type."
This is does not hold for the code example and so an explicit cast is required:
if (T.Verify() && T.isForwardDecl())
ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(),static_cast<llvm::Value*>(T)));
With this small change the code is both valid C++ 2003 and valid C++11.
I checked out the top of tree Clang and discovered that this change has already been made, which is great.