1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // template <class T1, class T2> struct pair
15 // pair& operator=(pair const& p);
21 #include "test_macros.h"
23 struct NonAssignable
{
26 NonAssignable
& operator=(NonAssignable
const&);
30 extern Incomplete inc_obj
;
32 struct ConstructibleFromInt
{
33 ConstructibleFromInt() : value(-1) { }
34 explicit ConstructibleFromInt(int v
) : value(v
) { }
41 // Test that we don't constrain the assignment operator in C++03 mode.
42 // Since we don't have access control SFINAE having pair evaluate SFINAE
43 // may cause a hard error.
44 typedef std::pair
<int, NonAssignable
> P
;
45 static_assert(std::is_copy_assignable
<P
>::value
, "");
48 typedef std::pair
<int, Incomplete
&> P
;
49 static_assert(std::is_copy_assignable
<P
>::value
, "");
51 assert(&p
.second
== &inc_obj
);
54 // The type is constructible from int, but not assignable from int.
55 // This ensures that operator=(pair const&) can be used in conjunction with
56 // pair(pair<U, V> const&) to mimic operator=(pair<U, V> const&) in C++03.
57 // This is weird but valid in C++03.
58 std::pair
<ConstructibleFromInt
, char> p
;
59 std::pair
<int, char> from(11, 'x');
61 assert(p
.first
.value
== 11);
62 assert(p
.second
== 'x');