From: Douglas Gregor Date: Tue, 22 Dec 2009 22:47:22 +0000 (+0000) Subject: Make sure that reinterpret_cast gets a CastKind on all successful X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2a5539ea74bc4c4637851395f6bf6f78689f4e6;p=clang Make sure that reinterpret_cast gets a CastKind on all successful paths. Fixes "cannot compile this unexpected cast lvalue yet" error in llvm/lib/Analysis/IPA/GlobalsModRef.cpp. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91932 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index 92eb1740c9..c9b3b8ec34 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -1053,8 +1053,11 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, return TC_NotApplicable; // If both types have the same size, we can successfully cast. - if (Self.Context.getTypeSize(SrcType) == Self.Context.getTypeSize(DestType)) + if (Self.Context.getTypeSize(SrcType) + == Self.Context.getTypeSize(DestType)) { + Kind = CastExpr::CK_BitCast; return TC_Success; + } if (destIsScalar) msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size; @@ -1083,6 +1086,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, // to the same type. However, the behavior of compilers is pretty consistent // on this point: allow same-type conversion if the involved types are // pointers, disallow otherwise. + Kind = CastExpr::CK_NoOp; return TC_Success; } diff --git a/test/CodeGenCXX/casts.cpp b/test/CodeGenCXX/casts.cpp index 91ae6af19e..436b722e69 100644 --- a/test/CodeGenCXX/casts.cpp +++ b/test/CodeGenCXX/casts.cpp @@ -5,6 +5,8 @@ namespace PR5248 { struct A { void copyFrom(const A &src); void addRef(void); + + A& operator=(int); }; void A::copyFrom(const A &src) { @@ -12,3 +14,7 @@ void A::copyFrom(const A &src) { } } +// reinterpret_cast to self +void test(PR5248::A* a) { + reinterpret_cast(*a) = 17; +}