[libcxx-commits] [libcxx] [libc++] Create a `constexpr` hash to use during constant evaluation (PR #214946)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Aug 23 10:33:55 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libcxx/test/support/constexpr_hash.h libcxx/test/std/utilities/function.objects/unord.hash/floating.pass.cpp libcxx/test/std/utilities/function.objects/unord.hash/integral.pass.cpp libcxx/test/support/poisoned_hash_helper.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/test/support/constexpr_hash.h b/libcxx/test/support/constexpr_hash.h
index e298500f6..e3f335853 100644
--- a/libcxx/test/support/constexpr_hash.h
+++ b/libcxx/test/support/constexpr_hash.h
@@ -25,7 +25,7 @@ struct constexpr_hash;
 
 template <DisabledForHash _Tp>
 struct constexpr_hash<_Tp> {
-  constexpr_hash()                                   = delete;
+  constexpr_hash()                                 = delete;
   constexpr_hash(const constexpr_hash&)            = delete;
   constexpr_hash& operator=(const constexpr_hash&) = delete;
 };
@@ -46,29 +46,28 @@ struct constexpr_hash<_Tp> {
         return region[multiple - 1]; // TODO: hash-ing
       }
     } else if constexpr (std::is_floating_point_v<_Tp>) {
-    if (__v == 0.0f)
-      return 0;
-    // return __scalar_hash<_Tp>::operator()(__v);
+      if (__v == 0.0f)
+        return 0;
+      // return __scalar_hash<_Tp>::operator()(__v);
 
-        constexpr size_t multiple = sizeof(_Tp) / sizeof(char);
-        std::array<char, multiple> region = std::bit_cast<std::array<char, multiple>>(__v);
+      constexpr size_t multiple         = sizeof(_Tp) / sizeof(char);
+      std::array<char, multiple> region = std::bit_cast<std::array<char, multiple>>(__v);
 
-        // TODO: pack indexing?
-        size_t res = 0;
-        for(size_t i = 0; i < multiple; ++i) {
-            res ^= region[i];
-        }
-        return res;
-
-        // TODO: 0, 1, 2, 3, 4
-        // return region[multiple - 1]; // TODO: hash-ing
-        // return 1234ULL;
+      // TODO: pack indexing?
+      size_t res = 0;
+      for (size_t i = 0; i < multiple; ++i) {
+        res ^= region[i];
+      }
+      return res;
 
+      // TODO: 0, 1, 2, 3, 4
+      // return region[multiple - 1]; // TODO: hash-ing
+      // return 1234ULL;
     }
     __builtin_unreachable(); // todo: revisit
   }
 
-  constexpr_hash() noexcept                          = default;
+  constexpr_hash() noexcept                        = default;
   constexpr_hash& operator=(const constexpr_hash&) = default;
 };
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/214946


More information about the libcxx-commits mailing list