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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Fri May 15 12:57:15 PDT 2026


================
@@ -15584,3 +15581,31 @@ void ASTContext::recordOffsetOfEvaluation(const OffsetOfExpr *E) {
   if (FieldDecl *FD = Comp.getField(); isPFPField(FD))
     PFPFieldsWithEvaluatedOffset.insert(FD);
 }
+
+bool ASTContext::maybeFoldMSConstexpr(
+    SmallVectorImpl<PartialDiagnosticAt> &Notes) {
+  if (Notes.size() != 1 || !getLangOpts().MSVCCompat)
+    return false;
+  auto &PD = Notes[0].second;
+  if (PD.getDiagID() != diag::note_constexpr_invalid_cast)
+    return false;
+  unsigned CastID;
+  switch (PD.getValueArg(0)) {
----------------
efriedma-quic wrote:

This is introducing a lot of complicated logic... maybe it's simpler to add `diag::note_constexpr_invalid_cast_ptrtoint`, so the case we care about has a unique ID?

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


More information about the cfe-commits mailing list