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

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 7 09:49:39 PDT 2026


================
@@ -6697,6 +6697,7 @@ Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
   SmallVector<PartialDiagnosticAt, 8> Notes;
   Expr::EvalResult Eval;
   Eval.Diag = &Notes;
+  Eval.IsConvertedExpr = true;
----------------
eleviant wrote:

Initially I've added this variable and a check to avoid emitting warning when implicit conversion is an error, i.e `TplBool<FIELD_OFFSET(S, y)>`. However I wonder if we can leave things as they are, so user sees:
```
/tmp/1.cpp:19:9: error: non-type template argument evaluates to 4, which cannot be narrowed to type 'bool' [-Wc++11-narrowing]
   19 | TplBool<FIELD_OFFSET(S, y)> tb;
      |         ^
/tmp/1.cpp:3:35: note: expanded from macro 'FIELD_OFFSET'
    3 | #define FIELD_OFFSET(type, field) ((LONG_PTR)&(((type *)0)->field))
      |                                   ^
/tmp/1.cpp:19:9: warning: folding constant expression involving cast that performs the conversions of a reinterpret_cast is a Microsoft extension
```
So far I removed it in latest update. But still I'm wondering: can this warning really appear more than once for the same expression?

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


More information about the cfe-commits mailing list