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>
2362
2362
bool CastPointerIntegral (InterpState &S, CodePtr OpPC) {
2363
2363
const Pointer &Ptr = S.Stk .pop <Pointer>();
2364
2364
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
+
2365
2369
if (!CheckPointerToIntegralCast (S, OpPC, Ptr, T::bitWidth ()))
2366
- return false ;
2370
+ return Invalid (S, OpPC) ;
2367
2371
2368
2372
S.Stk .push <T>(T::from (Ptr.getIntegerRepresentation ()));
2369
2373
return true ;
Original file line number Diff line number Diff line change @@ -221,3 +221,15 @@ namespace PseudoDtor {
221
221
static_assert (f() == 0 , " " ); // both-error {{constant expression}} \
222
222
// expected-note {{in call to}}
223
223
}
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