Skip to content

Commit

Permalink
Allow the use of pointers to const within PointerUnion.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68159 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
DougGregor committed Mar 31, 2009
1 parent b160f5d commit 4122282
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions include/llvm/ADT/PointerUnion.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ namespace llvm {
PointerUnion() {}

PointerUnion(PT1 V) {
Val.setPointer(PointerLikeTypeTraits<PT1>::getAsVoidPointer(V));
Val.setPointer(
const_cast<void *>(PointerLikeTypeTraits<PT1>::getAsVoidPointer(V)));
Val.setInt(0);
}
PointerUnion(PT2 V) {
Val.setPointer(PointerLikeTypeTraits<PT2>::getAsVoidPointer(V));
Val.setPointer(
const_cast<void *>(PointerLikeTypeTraits<PT2>::getAsVoidPointer(V)));
Val.setInt(1);
}

Expand Down Expand Up @@ -109,12 +111,14 @@ namespace llvm {
/// Assignment operators - Allow assigning into this union from either
/// pointer type, setting the discriminator to remember what it came from.
const PointerUnion &operator=(const PT1 &RHS) {
Val.setPointer(PointerLikeTypeTraits<PT1>::getAsVoidPointer(RHS));
Val.setPointer(
const_cast<void *>(PointerLikeTypeTraits<PT1>::getAsVoidPointer(RHS)));
Val.setInt(0);
return *this;
}
const PointerUnion &operator=(const PT2 &RHS) {
Val.setPointer(PointerLikeTypeTraits<PT2>::getAsVoidPointer(RHS));
Val.setPointer(
const_cast<void *>(PointerLikeTypeTraits<PT2>::getAsVoidPointer(RHS)));
Val.setInt(1);
return *this;
}
Expand Down

0 comments on commit 4122282

Please sign in to comment.