[libcxx-commits] [libcxx] [libc++][test] Make tests for constexpr `hash<vector<bool>>` libc++-specific (PR #132617)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 24 10:19:23 PDT 2025


================
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++20
+
+// <vector>
+
+// template<class Allocator> struct hash<vector<bool, Allocator>>;
+
+// libc++ makes the operator() of this partial specialization constexpr since C++20, which is a conforming extension.
+
+#include <cassert>
+#include <vector>
+
+#include "min_allocator.h"
+#include "poisoned_hash_helper.h"
+
+constexpr bool test() {
+  {
+    using VB = std::vector<bool>;
+    bool ba[]{true, false, true, true, false};
+    VB vb(std::begin(ba), std::end(ba));
+
+    const std::hash<VB> h{};
+    const auto hash_value = h(vb);
+    assert(hash_value == h(vb));
+    assert(hash_value != 0);
----------------
mordante wrote:

Can you refactor this to a separate function and test that for the different vector types?

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


More information about the libcxx-commits mailing list