Skip to content

Commit

Permalink
Fix a bug in -Wundefined-reinterpret-cast where we failed to look
Browse files Browse the repository at this point in the history
through sugared types when testing for TagTypes. This was the actual
cause of the only false positive in Clang+LLVM.

Next evaluation will be over a much larger selection of code including
large amounts of open source code.

llvm-svn: 131957
  • Loading branch information
chandlerc committed May 24, 2011
1 parent 46e1ebf commit 0dc3f8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaCXXCast.cpp
Expand Up @@ -1330,7 +1330,7 @@ void Sema::CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType,
return;
}
// or one of the types is a tag type.
if (isa<TagType>(SrcTy) || isa<TagType>(DestTy)) {
if (SrcTy->getAs<TagType>() || DestTy->getAs<TagType>()) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaCXX/reinterpret-cast.cpp
Expand Up @@ -119,9 +119,13 @@ namespace PR9564 {

void dereference_reinterpret_cast() {
struct A {};
typedef A A2;
class B {};
typedef B B2;
A a;
B b;
A2 a2;
B2 b2;
long l;
double d;
float f;
Expand All @@ -142,6 +146,10 @@ void dereference_reinterpret_cast() {
(void)*reinterpret_cast<A*>(&b);
(void)reinterpret_cast<B&>(a);
(void)*reinterpret_cast<B*>(&a);
(void)reinterpret_cast<A2&>(b2);
(void)*reinterpret_cast<A2*>(&b2);
(void)reinterpret_cast<B2&>(a2);
(void)*reinterpret_cast<B2*>(&a2);

// Casting to itself is allowed
(void)reinterpret_cast<A&>(a);
Expand Down

0 comments on commit 0dc3f8d

Please sign in to comment.