diff options
author | Louis Dionne <ldionne@apple.com> | 2019-09-26 14:51:10 +0000 |
---|---|---|
committer | Louis Dionne <ldionne@apple.com> | 2019-09-26 14:51:10 +0000 |
commit | e16f2cb6789286dbfa4a184cef25b91dfb499206 (patch) | |
tree | f67676d1b91559354b68e3e9860e0ee4aae2705f /libcxx/test/std/utilities/utility/pairs | |
parent | 1822087facdfaeac69dcd14690866a4d872e3fdb (diff) | |
download | bcm5719-llvm-e16f2cb6789286dbfa4a184cef25b91dfb499206.tar.gz bcm5719-llvm-e16f2cb6789286dbfa4a184cef25b91dfb499206.zip |
[libc++] Take 2: Implement LWG 2510
Summary:
LWG2510 makes tag types like allocator_arg_t explicitly default
constructible instead of implicitly default constructible. It also
makes the constructors for std::pair and std::tuple conditionally
explicit based on the explicit-ness of the default constructibility
for the pair/tuple's elements.
This was previously committed as r372777 and reverted in r372832 due to
the commit breaking LLVM's build in C++14 mode. This issue has now been
addressed.
Reviewers: mclow.lists
Subscribers: christof, jkorous, dexonsmith, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D65161
llvm-svn: 372983
Diffstat (limited to 'libcxx/test/std/utilities/utility/pairs')
5 files changed, 102 insertions, 2 deletions
diff --git a/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp index d70d060deb0..903aa935583 100644 --- a/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct.pass.cpp @@ -12,7 +12,7 @@ // template <class T1, class T2> struct pair -// struct piecewise_construct_t { }; +// struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; // constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); #include <utility> diff --git a/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.fail.cpp b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.fail.cpp new file mode 100644 index 00000000000..b8dd28a5764 --- /dev/null +++ b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// Before GCC 6, aggregate initialization kicks in. +// See https://stackoverflow.com/q/41799015/627587. +// UNSUPPORTED: gcc-5 + +// <utility> + +// struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; +// constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); + +// This test checks for LWG 2510. + +#include <utility> + + +std::piecewise_construct_t f() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} + +int main(int, char**) { + return 0; +} diff --git a/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.pass.cpp new file mode 100644 index 00000000000..0fdba067487 --- /dev/null +++ b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <utility> + +// struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; +// constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); + +#include <utility> + + +int main(int, char**) { + std::piecewise_construct_t x = std::piecewise_construct; + (void)x; + + return 0; +} diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.explicit.fail.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.explicit.fail.cpp new file mode 100644 index 00000000000..511f21ec301 --- /dev/null +++ b/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.explicit.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// Before GCC 6, aggregate initialization kicks in. +// See https://stackoverflow.com/q/41799015/627587. +// UNSUPPORTED: gcc-5 + +// <utility> + +// template <class T1, class T2> struct pair + +// explicit(see-below) constexpr pair(); + +// This test checks the conditional explicitness of std::pair's default +// constructor as introduced by the resolution of LWG 2510. + +#include <utility> + + +struct ImplicitlyDefaultConstructible { + ImplicitlyDefaultConstructible() = default; +}; + +struct ExplicitlyDefaultConstructible { + explicit ExplicitlyDefaultConstructible() = default; +}; + +std::pair<ImplicitlyDefaultConstructible, ExplicitlyDefaultConstructible> test1() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::pair<ExplicitlyDefaultConstructible, ImplicitlyDefaultConstructible> test2() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::pair<ExplicitlyDefaultConstructible, ExplicitlyDefaultConstructible> test3() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::pair<ImplicitlyDefaultConstructible, ImplicitlyDefaultConstructible> test4() { return {}; } + +int main(int, char**) { + return 0; +} diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp index 049c2206088..dc05a2b4885 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -10,7 +10,7 @@ // template <class T1, class T2> struct pair -// constexpr pair(); +// explicit(see-below) constexpr pair(); // NOTE: The SFINAE on the default constructor is tested in // default-sfinae.pass.cpp @@ -45,6 +45,11 @@ int main(int, char**) using P2 = std::pair<NoDefault, int>; static_assert(!std::is_default_constructible<P2>::value, ""); } + { + struct Base { }; + struct Derived : Base { protected: Derived() = default; }; + static_assert(!std::is_default_constructible<std::pair<Derived, int> >::value, ""); + } #endif return 0; |