From 1f8f2d52ff3712770a49f318a687b0c8b0ada9d0 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 24 May 2011 07:43:19 +0000 Subject: [PATCH] Fix a bug in -Wundefined-reinterpret-cast where we failed to look 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 | 2 +- test/SemaCXX/reinterpret-cast.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index c7038322e1..32fd0be375 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -1330,7 +1330,7 @@ void Sema::CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, return; } // or one of the types is a tag type. - if (isa(SrcTy) || isa(DestTy)) { + if (SrcTy->getAs() || DestTy->getAs()) { return; } diff --git a/test/SemaCXX/reinterpret-cast.cpp b/test/SemaCXX/reinterpret-cast.cpp index 449fecb160..68005a5270 100644 --- a/test/SemaCXX/reinterpret-cast.cpp +++ b/test/SemaCXX/reinterpret-cast.cpp @@ -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(&b); (void)reinterpret_cast(a); (void)*reinterpret_cast(&a); + (void)reinterpret_cast(b2); + (void)*reinterpret_cast(&b2); + (void)reinterpret_cast(a2); + (void)*reinterpret_cast(&a2); // Casting to itself is allowed (void)reinterpret_cast(a);