File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -2362,8 +2362,12 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
23622362bool CastPointerIntegral (InterpState &S, CodePtr OpPC) {
23632363 const Pointer &Ptr = S.Stk .pop <Pointer>();
23642364
2365+ S.CCEDiag (S.Current ->getSource (OpPC), diag::note_constexpr_invalid_cast)
2366+ << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret
2367+ << S.getLangOpts ().CPlusPlus << S.Current ->getRange (OpPC);
2368+
23652369 if (!CheckPointerToIntegralCast (S, OpPC, Ptr, T::bitWidth ()))
2366- return false ;
2370+ return Invalid (S, OpPC) ;
23672371
23682372 S.Stk .push <T>(T::from (Ptr.getIntegerRepresentation ()));
23692373 return true ;
Original file line number Diff line number Diff line change @@ -221,3 +221,15 @@ namespace PseudoDtor {
221221 static_assert (f() == 0 , " " ); // both-error {{constant expression}} \
222222 // expected-note {{in call to}}
223223}
224+
225+ namespace IntToPtrCast {
226+ typedef __INTPTR_TYPE__ intptr_t ;
227+
228+ constexpr intptr_t f (intptr_t x) {
229+ return (((x) >> 21 ) * 8 );
230+ }
231+
232+ extern " C" int foo;
233+ constexpr intptr_t i = f((intptr_t )&foo - 10 ); // both-error{{constexpr variable 'i' must be initialized by a constant expression}} \
234+ // both-note{{reinterpret_cast}}
235+ }
You can’t perform that action at this time.
0 commit comments