[clang] [clang] Allow C-style casts in constexpr in MS compatible mode (PR #197005)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 1 07:17:23 PDT 2026


================
@@ -8533,7 +8533,9 @@ class ExprEvaluatorBase
   }
 
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
-    CCEDiag(E, diag::note_constexpr_invalid_cast)
+    bool IsPtrToInt = E->getCastKind() == CK_PointerToIntegral;
+    CCEDiag(E, IsPtrToInt ? diag::note_constexpr_invalid_cast_ptrtoint
+                          : diag::note_constexpr_invalid_cast)
----------------
eleviant wrote:

> we want to throw away the note about the ptrtoint cast if we see a more important error.

I tried this in the latest commit. The only error which is passed after invalid_cast_ptrtoint is null_subobject. For everything else existing diagnostic is cleared. This effectively limits the range of expressions we allow with `-fms-compatibility` with offsetof-like

https://github.com/llvm/llvm-project/pull/197005


More information about the cfe-commits mailing list