[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 22 23:05:41 PDT 2022


hubert.reinterpretcast added inline comments.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1905
+        if (SemaRef.LangOpts.CPlusPlus2b) {
+          if (!VD->getType()->isLiteralType(SemaRef.Context))
+            SemaRef.Diag(VD->getLocation(),
----------------
This seems to trigger even when the type is dependent:
```
<stdin>:1:36: warning: definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b [-Wpre-c++2b-compat]
auto qq = [](auto x) { decltype(x) n; };
                                   ^
1 warning generated.
```

This also seems to emit even when `Kind` is not `Sema::CheckConstexprKind::Diagnose` (unlike the `static`/`thread_local` case above). Is the `CheckLiteralType` logic not reusable for this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122249/new/

https://reviews.llvm.org/D122249



More information about the cfe-commits mailing list