[libcxx-commits] [libcxx] [libc++] Fix triviality of std::pair for trivially copyable types without an assignment operator (PR #95444)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 13 10:55:30 PDT 2024
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 a9883739571f0adbe33219a74a934be7f8bd4f62 88fc16f26588224762b42bb5ea0e469ad02a59dc -- libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivially_copyable.compile.pass.cpp libcxx/include/__utility/pair.h libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivial_copy_move.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp
index 1f5dae1232..7df3707b6a 100644
--- a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp
+++ b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp
@@ -28,127 +28,128 @@
#include "test_macros.h"
template <class T>
-struct HasNonTrivialABI : std::integral_constant<bool,
- !std::is_trivially_destructible<T>::value
- || (std::is_copy_constructible<T>::value && !std::is_trivially_copy_constructible<T>::value)
+struct HasNonTrivialABI
+ : std::integral_constant<
+ bool,
+ !std::is_trivially_destructible<T>::value ||
+ (std::is_copy_constructible<T>::value && !std::is_trivially_copy_constructible<T>::value)
#if TEST_STD_VER >= 11
- || (std::is_move_constructible<T>::value && !std::is_trivially_move_constructible<T>::value)
+ || (std::is_move_constructible<T>::value && !std::is_trivially_move_constructible<T>::value)
#endif
-> {};
+ > {
+};
#if TEST_STD_VER >= 11
struct NonTrivialDtor {
- NonTrivialDtor(NonTrivialDtor const&) = default;
- ~NonTrivialDtor();
+ NonTrivialDtor(NonTrivialDtor const&) = default;
+ ~NonTrivialDtor();
};
NonTrivialDtor::~NonTrivialDtor() {}
static_assert(HasNonTrivialABI<NonTrivialDtor>::value, "");
struct NonTrivialCopy {
- NonTrivialCopy(NonTrivialCopy const&);
+ NonTrivialCopy(NonTrivialCopy const&);
};
NonTrivialCopy::NonTrivialCopy(NonTrivialCopy const&) {}
static_assert(HasNonTrivialABI<NonTrivialCopy>::value, "");
struct NonTrivialMove {
- NonTrivialMove(NonTrivialMove const&) = default;
- NonTrivialMove(NonTrivialMove&&);
+ NonTrivialMove(NonTrivialMove const&) = default;
+ NonTrivialMove(NonTrivialMove&&);
};
NonTrivialMove::NonTrivialMove(NonTrivialMove&&) {}
static_assert(HasNonTrivialABI<NonTrivialMove>::value, "");
struct DeletedCopy {
- DeletedCopy(DeletedCopy const&) = delete;
- DeletedCopy(DeletedCopy&&) = default;
+ DeletedCopy(DeletedCopy const&) = delete;
+ DeletedCopy(DeletedCopy&&) = default;
};
static_assert(!HasNonTrivialABI<DeletedCopy>::value, "");
struct TrivialMove {
- TrivialMove(TrivialMove &&) = default;
+ TrivialMove(TrivialMove&&) = default;
};
static_assert(!HasNonTrivialABI<TrivialMove>::value, "");
struct Trivial {
- Trivial(Trivial const&) = default;
+ Trivial(Trivial const&) = default;
};
static_assert(!HasNonTrivialABI<Trivial>::value, "");
#endif
-
-void test_trivial()
-{
- {
- typedef std::pair<int, short> P;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
+void test_trivial() {
+ {
+ typedef std::pair<int, short> P;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
#if TEST_STD_VER >= 11
- {
- typedef std::pair<int, short> P;
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<NonTrivialDtor, int>;
- static_assert(!std::is_trivially_destructible<P>::value, "");
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<NonTrivialCopy, int>;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<NonTrivialMove, int>;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<DeletedCopy, int>;
- static_assert(!std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<Trivial, int>;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<TrivialMove, int>;
- static_assert(!std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasNonTrivialABI<P>::value, "");
- }
+ {
+ typedef std::pair<int, short> P;
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialDtor, int>;
+ static_assert(!std::is_trivially_destructible<P>::value, "");
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialCopy, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialMove, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<DeletedCopy, int>;
+ static_assert(!std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<Trivial, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<TrivialMove, int>;
+ static_assert(!std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasNonTrivialABI<P>::value, "");
+ }
#endif
}
void test_layout() {
- typedef std::pair<std::pair<char, char>, char> PairT;
- static_assert(sizeof(PairT) == 3, "");
- static_assert(TEST_ALIGNOF(PairT) == TEST_ALIGNOF(char), "");
- static_assert(offsetof(PairT, first) == 0, "");
+ typedef std::pair<std::pair<char, char>, char> PairT;
+ static_assert(sizeof(PairT) == 3, "");
+ static_assert(TEST_ALIGNOF(PairT) == TEST_ALIGNOF(char), "");
+ static_assert(offsetof(PairT, first) == 0, "");
}
int main(int, char**) {
- test_trivial();
- test_layout();
- return 0;
+ test_trivial();
+ test_layout();
+ return 0;
}
diff --git a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivial_copy_move.pass.cpp b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivial_copy_move.pass.cpp
index 3ec60c08b8..2cd6cb7b0c 100644
--- a/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivial_copy_move.pass.cpp
+++ b/libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivial_copy_move.pass.cpp
@@ -25,48 +25,51 @@
#include "test_macros.h"
template <class T>
-struct HasTrivialABI : std::integral_constant<bool,
- std::is_trivially_destructible<T>::value
- && (!std::is_copy_constructible<T>::value || std::is_trivially_copy_constructible<T>::value)
+struct HasTrivialABI
+ : std::integral_constant<
+ bool,
+ std::is_trivially_destructible<T>::value &&
+ (!std::is_copy_constructible<T>::value || std::is_trivially_copy_constructible<T>::value)
#if TEST_STD_VER >= 11
- && (!std::is_move_constructible<T>::value || std::is_trivially_move_constructible<T>::value)
+ && (!std::is_move_constructible<T>::value || std::is_trivially_move_constructible<T>::value)
#endif
-> {};
+ > {
+};
#if TEST_STD_VER >= 11
struct NonTrivialDtor {
- NonTrivialDtor(NonTrivialDtor const&) = default;
- ~NonTrivialDtor();
+ NonTrivialDtor(NonTrivialDtor const&) = default;
+ ~NonTrivialDtor();
};
NonTrivialDtor::~NonTrivialDtor() {}
static_assert(!HasTrivialABI<NonTrivialDtor>::value, "");
struct NonTrivialCopy {
- NonTrivialCopy(NonTrivialCopy const&);
+ NonTrivialCopy(NonTrivialCopy const&);
};
NonTrivialCopy::NonTrivialCopy(NonTrivialCopy const&) {}
static_assert(!HasTrivialABI<NonTrivialCopy>::value, "");
struct NonTrivialMove {
- NonTrivialMove(NonTrivialMove const&) = default;
- NonTrivialMove(NonTrivialMove&&);
+ NonTrivialMove(NonTrivialMove const&) = default;
+ NonTrivialMove(NonTrivialMove&&);
};
NonTrivialMove::NonTrivialMove(NonTrivialMove&&) {}
static_assert(!HasTrivialABI<NonTrivialMove>::value, "");
struct DeletedCopy {
- DeletedCopy(DeletedCopy const&) = delete;
- DeletedCopy(DeletedCopy&&) = default;
+ DeletedCopy(DeletedCopy const&) = delete;
+ DeletedCopy(DeletedCopy&&) = default;
};
static_assert(HasTrivialABI<DeletedCopy>::value, "");
struct TrivialMove {
- TrivialMove(TrivialMove &&) = default;
+ TrivialMove(TrivialMove&&) = default;
};
static_assert(HasTrivialABI<TrivialMove>::value, "");
struct Trivial {
- Trivial(Trivial const&) = default;
+ Trivial(Trivial const&) = default;
};
static_assert(HasTrivialABI<Trivial>::value, "");
#endif
@@ -83,100 +86,99 @@ struct TrivialNoConstruction {
TrivialNoConstruction& operator=(const TrivialNoConstruction&) = default;
};
-void test_trivial()
-{
- {
- typedef std::pair<int, short> P;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(HasTrivialABI<P>::value, "");
- }
+void test_trivial() {
+ {
+ typedef std::pair<int, short> P;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
#if TEST_STD_VER >= 11
- {
- typedef std::pair<int, short> P;
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(HasTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<NonTrivialDtor, int>;
- static_assert(!std::is_trivially_destructible<P>::value, "");
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(!HasTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<NonTrivialCopy, int>;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(!HasTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<NonTrivialMove, int>;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- static_assert(!HasTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<DeletedCopy, int>;
- static_assert(!std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<Trivial, int>;
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasTrivialABI<P>::value, "");
- }
- {
- using P = std::pair<TrivialMove, int>;
- static_assert(!std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(std::is_trivially_move_constructible<P>::value, "");
- static_assert(HasTrivialABI<P>::value, "");
- }
+ {
+ typedef std::pair<int, short> P;
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialDtor, int>;
+ static_assert(!std::is_trivially_destructible<P>::value, "");
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialCopy, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialMove, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<DeletedCopy, int>;
+ static_assert(!std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<Trivial, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<TrivialMove, int>;
+ static_assert(!std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
#endif
- {
- using P = std::pair<TrivialNoAssignment, int>;
- static_assert(std::is_trivially_copy_constructible<P>::value, "");
- static_assert(std::is_trivially_move_constructible<P>::value, "");
+ {
+ using P = std::pair<TrivialNoAssignment, int>;
+ static_assert(std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
#if TEST_STD_VER >= 11 // This is https://llvm.org/PR90605
- static_assert(!std::is_trivially_copy_assignable<P>::value, "");
- static_assert(!std::is_trivially_move_assignable<P>::value, "");
+ static_assert(!std::is_trivially_copy_assignable<P>::value, "");
+ static_assert(!std::is_trivially_move_assignable<P>::value, "");
#endif // TEST_STD_VER >= 11
- static_assert(std::is_trivially_destructible<P>::value, "");
- }
- {
- using P = std::pair<TrivialNoConstruction, int>;
+ static_assert(std::is_trivially_destructible<P>::value, "");
+ }
+ {
+ using P = std::pair<TrivialNoConstruction, int>;
#if TEST_STD_VER >= 11
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
#endif // TEST_STD_VER >= 11
- static_assert(!std::is_trivially_copy_assignable<P>::value, "");
- static_assert(!std::is_trivially_move_assignable<P>::value, "");
- static_assert(std::is_trivially_destructible<P>::value, "");
- }
+ static_assert(!std::is_trivially_copy_assignable<P>::value, "");
+ static_assert(!std::is_trivially_move_assignable<P>::value, "");
+ static_assert(std::is_trivially_destructible<P>::value, "");
+ }
}
void test_layout() {
- typedef std::pair<std::pair<char, char>, char> PairT;
- static_assert(sizeof(PairT) == 3, "");
- static_assert(TEST_ALIGNOF(PairT) == TEST_ALIGNOF(char), "");
- static_assert(offsetof(PairT, first) == 0, "");
+ typedef std::pair<std::pair<char, char>, char> PairT;
+ static_assert(sizeof(PairT) == 3, "");
+ static_assert(TEST_ALIGNOF(PairT) == TEST_ALIGNOF(char), "");
+ static_assert(offsetof(PairT, first) == 0, "");
}
int main(int, char**) {
- test_trivial();
- test_layout();
- return 0;
+ test_trivial();
+ test_layout();
+ return 0;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95444
More information about the libcxx-commits
mailing list