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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 23 05:17:45 PDT 2022


aaron.ballman added a comment.

I'm seeing precommit CI failures:

Failed Tests (1):

  Clang :: SemaCXX/constant-expression-cxx2b.cpp



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1905
+        if (SemaRef.LangOpts.CPlusPlus2b) {
+          if (!VD->getType()->isLiteralType(SemaRef.Context))
+            SemaRef.Diag(VD->getLocation(),
----------------
cor3ntin wrote:
> hubert.reinterpretcast wrote:
> > 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?
> You are right, thanks for noticing that, it was rather bogus.
> The reason I'm not using CheckLiteralType is to avoid duplicating a diagnostics message, as CheckLiteralType doesn't allow us to pass parameter to the diagnostic message.
> 
> It leaves us with an uncovered scenario though: We do not emit the warning on template instantiation, and I don't think there is an  easy way to do that.
> The reason I'm not using CheckLiteralType is to avoid duplicating a diagnostics message, as CheckLiteralType doesn't allow us to pass parameter to the diagnostic message.

Huh?

```
static bool CheckLiteralType(Sema &SemaRef, Sema::CheckConstexprKind Kind,
                             SourceLocation Loc, QualType T, unsigned DiagID,
                             Ts &&...DiagArgs) {
  ...
}
```
I would hope `DiagArgs` should do exactly that? :-)


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