Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[C++11 Compat] Fix breaking change in C++11 pair copyctor.
Browse files Browse the repository at this point in the history
While this code is valid C++98, it is not valid C++11. The problem can be
reduced to:

class MDNode;

class DIType {
  operator MDNode*() const {return 0;}
};

class WeakVH {
  WeakVH(MDNode*) {}
};

int main() {
  DIType di;
  std::pair<void*, WeakVH> p(std::make_pair((void*)0, di)));
}

This was not detected by any of the bots we have because they either compile
C++98 with libstdc++ (which allows it), or C++11 with libc++ (which incorrectly
allows it). I ran into the problem when compiling with VS 2012 RC.

Thanks to Richard for explaining the issue.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158245 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Bigcheese committed Jun 8, 2012
1 parent 092bf67 commit 50e3faa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/CodeGen/CGDebugInfo.cpp
Expand Up @@ -1700,7 +1700,8 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) {

llvm::DIType TC = getTypeOrNull(Ty);
if (TC.Verify() && TC.isForwardDecl())
ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(), TC));
ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(),
static_cast<llvm::Value*>(TC)));

// And update the type cache.
TypeCache[Ty.getAsOpaquePtr()] = Res;
Expand Down Expand Up @@ -1811,7 +1812,8 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(QualType Ty,
llvm::DIType Res = CreateLimitedTypeNode(Ty, Unit);

if (T.Verify() && T.isForwardDecl())
ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(), T));
ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(),
static_cast<llvm::Value*>(T)));

// And update the type cache.
TypeCache[Ty.getAsOpaquePtr()] = Res;
Expand Down

0 comments on commit 50e3faa

Please sign in to comment.