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

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 23 10:51:55 PDT 2026


================
@@ -18,6 +18,21 @@ using namespace clang::interp;
 
 State::~State() {}
 
+bool State::shouldRelaxDiag(const SourceLocation &Loc, diag::kind DiagId) {
+  if (!Ctx.getLangOpts().MSVCCompat)
----------------
eleviant wrote:

I'm not quite sure about that. I think we still want to relax constant expression evaluation even if we don't actually want to emit a warning after the evaluation has finished. In particular, this happens when we call `CheckTemplateArgument`, which in turn calls `BuildConvertedConstantExpression`. If we change the condition this way, the template argument in the statement below will no longer be considered a constant expression:

```
template<bool B>
struct TplBool {};

// template argument is not constant if we change condition in shouldRelaxDiag
TplBool<FIELD_OFFSET(S, y)> tc;
```

Strangely, this causes the code above to compile successfully instead of producing the following error:

```
a.cpp:16:9: error: non-type template argument evaluates to 4, which cannot be narrowed to type 'bool' [-Wc++11-narrowing]
```


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


More information about the cfe-commits mailing list