[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:06:37 PDT 2022


hubert.reinterpretcast added inline comments.


================
Comment at: clang/test/SemaCXX/constant-expression-cxx2b.cpp:219
+      NonLiteral n; // cxx2b-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}} \
+                    // cxx2b-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
     return 0;
----------------
Not sure how much we want the message in this case. The lambda is not marked `constexpr` (although it is implicitly `constexpr` in C++2b).

Note that we don't get a message for this:
```
auto qq = [] { return 0; static int x = 42; };
constexpr int qx = qq();
```

I am not sure how difficult it would be to come at this from the used-in-constant-evaluation side, but there is probably a larger class of messages in the same situation (so it would probably be a separate endeavour).


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