diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 3e53f2a2c8557..7cba0e8a4da19 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2990,6 +2990,8 @@ bool Compiler::VisitCXXReinterpretCastExpr( if (PointeeToT && PointeeFromT) { if (isIntegralType(*PointeeFromT) && isIntegralType(*PointeeToT)) Fatal = false; + } else { + Fatal = SubExpr->getType().getTypePtr() != E->getType().getTypePtr(); } if (!this->emitInvalidCast(CastKind::Reinterpret, Fatal, E)) diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 23582e9ab556a..4c69517304ea7 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -185,3 +185,11 @@ namespace InitLinkToRVO { constexpr A make() { return A {}; } static_assert(make().z == 4, ""); } + +namespace DynamicCast { + struct S { int x, y; } s; + constexpr S* sptr = &s; + struct Str { + int b : reinterpret_cast(sptr) == reinterpret_cast(sptr); + }; +}