This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Recognize "if consteval".
ClosedPublic

Authored by curdeius on Mar 2 2022, 3:14 AM.

Diff Detail

Event Timeline

curdeius created this revision.Mar 2 2022, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 3:14 AM
curdeius requested review of this revision.Mar 2 2022, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 3:14 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MyDeveloperDay accepted this revision.Mar 2 2022, 5:32 AM

LFTM

Do we also need to consider this in the context of "AllowShortIfStatments"? (that would be in a different review in my view)

This revision is now accepted and ready to land.Mar 2 2022, 5:32 AM

LFTM

Do we also need to consider this in the context of "AllowShortIfStatments"? (that would be in a different review in my view)

Definitely. Since it didn't work at all, I reported it without a .clang-format. I was hoping it'd play well with AllowShortIfStatments out of the box.
I'm currently building HEAD with this patch to reformat my code.

I'll handle AllowShortIfStatements and update this review. Should be pretty straightforward.

JohelEGP accepted this revision.Mar 2 2022, 8:18 AM

My few cases format consistently with the condition case:

diff
diff --git a/tests/integration/test.waarudo.io.dynamic.cpp b/tests/integration/test.waarudo.io.dynamic.cpp
index be5a626..e1265b9 100644
--- a/tests/integration/test.waarudo.io.dynamic.cpp
+++ b/tests/integration/test.waarudo.io.dynamic.cpp
@@ -21,7 +21,7 @@ public:
   }
 
   constexpr ~input_source() {
-    if (std::is_constant_evaluated()) {
+    if consteval {
       expects(input_byte == previous_input_byte);
     } else {
       std::ofstream{"test.waarudo.io.dynamic.previous.input.byte.txt"} << "waarudo::byte{'"
@@ -37,7 +37,7 @@ public:
   [[nodiscard]] constexpr waarudo::output_bytes output() override { return {&output_byte, 1z}; }
 
   constexpr ~output_destination() {
-    if (std::is_constant_evaluated()) {
+    if consteval {
       expects(output_byte == previous_output_byte);
     } else {
       std::cout << std::bit_cast<char>(output_byte);
diff --git a/tests/waarudo.test.utilities.cpp b/tests/waarudo.test.utilities.cpp
index ed82b2b..f4ec8e3 100644
--- a/tests/waarudo.test.utilities.cpp
+++ b/tests/waarudo.test.utilities.cpp
@@ -13,7 +13,7 @@ export template<auto F> concept constant_invocable = requires { typename std::in
 export using waarudo::expects;
 
 export constexpr void runtime(void (*const f)()) {
-  if (not std::is_constant_evaluated()) f();
+  if not consteval { f(); }
 }
 
 template<std::integral I, std::invocable<I> F> void visit_values(F f) {

Thank you.

Great, I'll add a few test cases when landing.

This revision was automatically updated to reflect the committed changes.
HazardyKnusperkeks added a project: Restricted Project.Mar 2 2022, 12:02 PM