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 | |
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')
9 files changed, 193 insertions, 6 deletions
diff --git a/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.fail.cpp b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.fail.cpp new file mode 100644 index 00000000000..fb991d425f1 --- /dev/null +++ b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.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 + +// <memory> + +// struct allocator_arg_t { explicit allocator_arg_t() = default; }; +// const allocator_arg_t allocator_arg = allocator_arg_t(); + +// This test checks for LWG 2510. + +#include <memory> + + +std::allocator_arg_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/memory/allocator.tag/allocator_arg.pass.cpp b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp index 0253243319a..e22bec1e514 100644 --- a/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp @@ -8,7 +8,7 @@ // <memory> -// struct allocator_arg_t { }; +// struct allocator_arg_t { explicit allocator_arg_t() = default; }; // const allocator_arg_t allocator_arg = allocator_arg_t(); #include <memory> @@ -21,5 +21,5 @@ int main(int, char**) { test(std::allocator_arg); - return 0; + return 0; } diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.fail.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.fail.cpp new file mode 100644 index 00000000000..616550f60e5 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.fail.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <tuple> + +// template <class... Types> class tuple; + +// explicit(see-below) constexpr tuple(); + +#include <tuple> + + +struct Implicit { + Implicit() = default; +}; + +struct Explicit { + explicit Explicit() = default; +}; + +std::tuple<> test1() { return {}; } + +std::tuple<Implicit> test2() { return {}; } +std::tuple<Explicit> test3() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} + +std::tuple<Implicit, Implicit> test4() { return {}; } +std::tuple<Explicit, Implicit> test5() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Implicit, Explicit> test6() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Explicit, Explicit> test7() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} + +std::tuple<Implicit, Implicit, Implicit> test8() { return {}; } +std::tuple<Implicit, Implicit, Explicit> test9() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Implicit, Explicit, Implicit> test10() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Implicit, Explicit, Explicit> test11() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Explicit, Implicit, Implicit> test12() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Explicit, Implicit, Explicit> test13() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Explicit, Explicit, Implicit> test14() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::tuple<Explicit, Explicit, Explicit> test15() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} + +int main(int, char**) { + return 0; +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp index 46fd35ad4dd..c5b650d79a1 100644 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp @@ -10,7 +10,7 @@ // template <class... Types> class tuple; -// constexpr tuple(); +// explicit(see-below) constexpr tuple(); // UNSUPPORTED: c++98, c++03 @@ -107,6 +107,11 @@ int main(int, char**) IllFormedDefault v(0); std::tuple<IllFormedDefault> t(v); } + { + struct Base { }; + struct Derived : Base { protected: Derived() = default; }; + static_assert(!std::is_default_constructible<std::tuple<Derived, int> >::value, ""); + } - return 0; + return 0; } 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; |