]> granicus.if.org Git - clang/commitdiff
Fix a bug in -Wundefined-reinterpret-cast where we failed to look
authorChandler Carruth <chandlerc@gmail.com>
Tue, 24 May 2011 07:43:19 +0000 (07:43 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 24 May 2011 07:43:19 +0000 (07:43 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131957 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCXXCast.cpp
test/SemaCXX/reinterpret-cast.cpp

index c7038322e1c3950cb0d58aa0293609fa2ea0c0ed..32fd0be375ef9ede5d7df7a254bde5cac36b2611 100644 (file)
@@ -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;
   }
 
index 449fecb1607b4888468286a0e7f9b5176b0ae6c6..68005a5270e41a7e775f4a803d4c5c3ffa1e114f 100644 (file)
@@ -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;
@@ -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);