forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Fix triviality of std::pair for trivially copyable types wit…
…hout an assignment operator (llvm#95444) Since 83ead2b, std::pair would not be trivially copyable when it holds a trivially copyable type without an assignment operator. That is because pair gained an elligible copy-assignment-operator (the const version) in 83ead2b in C++ >= 23. This means that the trivially copyable property of std::pair for such types would be inconsistent between C++11/14/17/20 (trivially copyable) and C++23/26 (not trivially copyable). This patch makes std::pair's behavior consistent in all Standard modes EXCEPT C++03, which is a pre-existing condition and we have no way of changing (also, it shouldn't matter because the std::is_trivially_copyable trait was introduced in C++11). While this is not technically an ABI break, in practice we do know that folks sometimes use a different representation based on whether a type is trivially copyable. So we're treating 83ead2b as an ABI break and this patch is fixing said breakage. This patch also adds tests stolen from llvm#89652 that pin down the ABI of std::pair with respect to being trivially copyable. Fixes llvm#95428
- Loading branch information
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...xx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.trivially_copyable.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// | ||
// This test pins down the ABI of std::pair with respect to being "trivially copyable". | ||
// | ||
|
||
// This test doesn't work when the deprecated ABI to turn off pair triviality is enabled. | ||
// See libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp instead. | ||
// UNSUPPORTED: libcpp-deprecated-abi-disable-pair-trivial-copy-ctor | ||
|
||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "test_macros.h" | ||
|
||
struct trivially_copyable { | ||
int arr[4]; | ||
}; | ||
|
||
struct trivially_copyable_no_copy_assignment { | ||
int arr[4]; | ||
trivially_copyable_no_copy_assignment& operator=(const trivially_copyable_no_copy_assignment&) = delete; | ||
}; | ||
static_assert(std::is_trivially_copyable<trivially_copyable_no_copy_assignment>::value, ""); | ||
|
||
struct trivially_copyable_no_move_assignment { | ||
int arr[4]; | ||
trivially_copyable_no_move_assignment& operator=(const trivially_copyable_no_move_assignment&) = delete; | ||
}; | ||
static_assert(std::is_trivially_copyable<trivially_copyable_no_move_assignment>::value, ""); | ||
|
||
struct trivially_copyable_no_construction { | ||
int arr[4]; | ||
trivially_copyable_no_construction() = default; | ||
trivially_copyable_no_construction(const trivially_copyable_no_construction&) = delete; | ||
trivially_copyable_no_construction& operator=(const trivially_copyable_no_construction&) = default; | ||
}; | ||
static_assert(std::is_trivially_copyable<trivially_copyable_no_construction>::value, ""); | ||
|
||
static_assert(!std::is_trivially_copyable<std::pair<int&, int> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<int, int&> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<int&, int&> >::value, ""); | ||
|
||
static_assert(!std::is_trivially_copyable<std::pair<int, int> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<int, char> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<char, int> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<std::pair<char, char>, int> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable, int> >::value, ""); | ||
#if TEST_STD_VER == 03 // Known ABI difference | ||
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_copy_assignment, int> >::value, ""); | ||
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_move_assignment, int> >::value, ""); | ||
#else | ||
static_assert(std::is_trivially_copyable<std::pair<trivially_copyable_no_copy_assignment, int> >::value, ""); | ||
static_assert(std::is_trivially_copyable<std::pair<trivially_copyable_no_move_assignment, int> >::value, ""); | ||
#endif | ||
static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_construction, int> >::value, ""); | ||
|
||
static_assert(std::is_trivially_copy_constructible<std::pair<int, int> >::value, ""); | ||
static_assert(std::is_trivially_move_constructible<std::pair<int, int> >::value, ""); | ||
static_assert(!std::is_trivially_copy_assignable<std::pair<int, int> >::value, ""); | ||
static_assert(!std::is_trivially_move_assignable<std::pair<int, int> >::value, ""); | ||
static_assert(std::is_trivially_destructible<std::pair<int, int> >::value, ""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters