[libcxx-commits] [PATCH] D135635: [libc++] Add a missing include to `swap_allocator.h`.
Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 29 14:04:14 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe67903eb155e: [libc++] Add a missing include to `swap_allocator.h`. (authored by var-const, committed by varconst <varconsteq at gmail.com>).
Changed prior to commit:
https://reviews.llvm.org/D135635?vs=466848&id=478720#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D135635/new/
https://reviews.llvm.org/D135635
Files:
libcxx/test/libcxx/memory/swap_allocator.pass.cpp
Index: libcxx/test/libcxx/memory/swap_allocator.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/memory/swap_allocator.pass.cpp
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+
+// <memory>
+
+// template <typename _Alloc>
+// void __swap_allocator(_Alloc& __a1, _Alloc& __a2);
+
+#include <cassert>
+#include <memory>
+// Transitively includes `swap_allocator.h` (directly including it breaks the modules build).
+#include <vector>
+#include <utility>
+
+#include "test_macros.h"
+
+template <bool Propagate, bool Noexcept>
+struct Alloc {
+ int i = 0;
+ Alloc() = default;
+ Alloc(int set_i) : i(set_i) {}
+
+ using value_type = int;
+ using propagate_on_container_swap = std::integral_constant<bool, Propagate>;
+
+ friend void swap(Alloc& a1, Alloc& a2) TEST_NOEXCEPT_COND(Noexcept) {
+ std::swap(a1.i, a2.i);
+ }
+
+};
+
+using PropagatingAlloc = Alloc</*Propagate=*/true, /*Noexcept=*/true>;
+static_assert(std::allocator_traits<PropagatingAlloc>::propagate_on_container_swap::value, "");
+
+using NonPropagatingAlloc = Alloc</*Propagate=*/false, /*Noexcept=*/true>;
+static_assert(!std::allocator_traits<NonPropagatingAlloc>::propagate_on_container_swap::value, "");
+
+using NoexceptSwapAlloc = Alloc</*Propagate=*/true, /*Noexcept=*/true>;
+using ThrowingSwapAlloc = Alloc</*Propagate=*/true, /*Noexcept=*/false>;
+
+int main(int, char**) {
+ {
+ PropagatingAlloc a1(1), a2(42);
+ std::__swap_allocator(a1, a2);
+ assert(a1.i == 42);
+ assert(a2.i == 1);
+ }
+
+ {
+ NonPropagatingAlloc a1(1), a2(42);
+ std::__swap_allocator(a1, a2);
+ assert(a1.i == 1);
+ assert(a2.i == 42);
+ }
+
+#if TEST_STD_VER >= 11
+ {
+ NoexceptSwapAlloc noexcept_alloc;
+ static_assert(noexcept(std::__swap_allocator(noexcept_alloc, noexcept_alloc)), "");
+ }
+
+#if TEST_STD_VER > 11
+ { // From C++14, `__swap_allocator` is unconditionally noexcept.
+ ThrowingSwapAlloc throwing_alloc;
+ static_assert(noexcept(std::__swap_allocator(throwing_alloc, throwing_alloc)), "");
+ }
+#else
+ { // Until C++14, `__swap_allocator` is only noexcept if the underlying `swap` function is `noexcept`.
+ ThrowingSwapAlloc throwing_alloc;
+ static_assert(!noexcept(std::__swap_allocator(throwing_alloc, throwing_alloc)), "");
+ }
+#endif // TEST_STD_VER > 11
+#endif // TEST_STD_VER >= 11
+
+ return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135635.478720.patch
Type: text/x-patch
Size: 2758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221129/75996b3a/attachment.bin>
More information about the libcxx-commits
mailing list