[PATCH] D117613: [ASTMatchers] Add `isConsteval` matcher

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 19 09:46:27 PST 2022


aaron.ballman added reviewers: cor3ntin, sammccall.
aaron.ballman added a comment.

Adding a few more reviewers in case there are differing opinions.



================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:5173-5174
 
+/// Matches consteval function declarations,
+///        and if consteval.
+///
----------------



================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:5179
+///   consteval int bar();
+///   void baz() { if consteval {} }
+/// \endcode
----------------
It'd be good to show an example of:
```
if ! consteval {}

if ! consteval {} else {}
```
as well so users know what to expect.

Should there be a matcher so users can distinguish between `if consteval` and `if ! consteval`?

Test cases for these sort of things would also be appreciated.


================
Comment at: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:1794-1796
+  if (!GetParam().isCXX20OrLater()) {
+    return;
+  }
----------------



================
Comment at: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:1807-1809
+  if (!GetParam().isCXX20OrLater()) {
+    return;
+  }
----------------
Izaron wrote:
> Actually `if consteval` is a C++23 feature, but there is no `isCXX23orLater()` method. The `is consteval` construction seems to be backported to C++20 in clang, as it compiles and just emits a warning
> ```
> warning: consteval if is a C++2b extension [-Wc++2b-extensions]
> ```
Yes, we support `if consteval` as an extension in older language modes, so I think this is reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117613



More information about the cfe-commits mailing list