diff options
author | Louis Dionne <ldionne@apple.com> | 2019-09-24 20:18:54 +0000 |
---|---|---|
committer | Louis Dionne <ldionne@apple.com> | 2019-09-24 20:18:54 +0000 |
commit | 95411dd426e6ea5b13c8f1bb7c4ba7190ecd6c1a (patch) | |
tree | c855a112fdf1c8beb265b722df01b8f8d95e113f /libcxx/test | |
parent | 19712415a57509f722c0552550cbc308c25bde7b (diff) | |
download | bcm5719-llvm-95411dd426e6ea5b13c8f1bb7c4ba7190ecd6c1a.tar.gz bcm5719-llvm-95411dd426e6ea5b13c8f1bb7c4ba7190ecd6c1a.zip |
[libc++] 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.
Reviewers: mclow.lists, EricWF
Subscribers: christof, jkorous, dexonsmith, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D65161
llvm-svn: 372777
Diffstat (limited to 'libcxx/test')
14 files changed, 306 insertions, 10 deletions
diff --git a/libcxx/test/libcxx/type_traits/is_implicitly_default_constructible.pass.cpp b/libcxx/test/libcxx/type_traits/is_implicitly_default_constructible.pass.cpp new file mode 100644 index 00000000000..19719a79c0c --- /dev/null +++ b/libcxx/test/libcxx/type_traits/is_implicitly_default_constructible.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <type_traits> + +// __is_implicitly_default_constructible<Tp> + +#include <type_traits> + + +struct ExplicitlyDefaultConstructible1 { + explicit ExplicitlyDefaultConstructible1() = default; +}; + +struct ExplicitlyDefaultConstructible2 { + explicit ExplicitlyDefaultConstructible2() { } +}; + +struct ImplicitlyDefaultConstructible1 { + ImplicitlyDefaultConstructible1() { } +}; + +struct ImplicitlyDefaultConstructible2 { + ImplicitlyDefaultConstructible2() = default; +}; + +struct NonDefaultConstructible1 { + NonDefaultConstructible1() = delete; +}; + +struct NonDefaultConstructible2 { + explicit NonDefaultConstructible2() = delete; +}; + +struct NonDefaultConstructible3 { + NonDefaultConstructible3(NonDefaultConstructible3&&) { } +}; + +static_assert(!std::__is_implicitly_default_constructible<ExplicitlyDefaultConstructible1>::value, ""); +static_assert(!std::__is_implicitly_default_constructible<ExplicitlyDefaultConstructible2>::value, ""); +static_assert(std::__is_implicitly_default_constructible<ImplicitlyDefaultConstructible1>::value, ""); +static_assert(std::__is_implicitly_default_constructible<ImplicitlyDefaultConstructible2>::value, ""); +static_assert(!std::__is_implicitly_default_constructible<NonDefaultConstructible1>::value, ""); +static_assert(!std::__is_implicitly_default_constructible<NonDefaultConstructible2>::value, ""); +static_assert(!std::__is_implicitly_default_constructible<NonDefaultConstructible3>::value, ""); + +int main(int, char**) { + return 0; +} diff --git a/libcxx/test/std/language.support/support.dynamic/nothrow_t.fail.cpp b/libcxx/test/std/language.support/support.dynamic/nothrow_t.fail.cpp new file mode 100644 index 00000000000..c1092c3516b --- /dev/null +++ b/libcxx/test/std/language.support/support.dynamic/nothrow_t.fail.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// struct nothrow_t { +// explicit nothrow_t() = default; +// }; +// extern const nothrow_t nothrow; + +// This test checks for LWG 2510. + +#include <new> + + +std::nothrow_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/language.support/support.dynamic/nothrow_t.pass.cpp b/libcxx/test/std/language.support/support.dynamic/nothrow_t.pass.cpp new file mode 100644 index 00000000000..3a6231329f0 --- /dev/null +++ b/libcxx/test/std/language.support/support.dynamic/nothrow_t.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// struct nothrow_t { +// explicit nothrow_t() = default; +// }; +// extern const nothrow_t nothrow; + +#include <new> + + +int main(int, char**) { + std::nothrow_t x = std::nothrow; + (void)x; + + return 0; +} diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/types.fail.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/types.fail.cpp new file mode 100644 index 00000000000..56fbc90a63d --- /dev/null +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/types.fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// struct defer_lock_t { explicit defer_lock_t() = default; }; +// struct try_to_lock_t { explicit try_to_lock_t() = default; }; +// struct adopt_lock_t { explicit adopt_lock_t() = default; }; + +// This test checks for LWG 2510. + +#include <mutex> + + +std::defer_lock_t f1() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::try_to_lock_t f2() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} +std::adopt_lock_t f3() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}} + +int main(int, char**) { + return 0; +} diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp index 84c39baafa6..c03ca4622aa 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp @@ -10,16 +10,15 @@ // <mutex> -// struct defer_lock_t {}; -// struct try_to_lock_t {}; -// struct adopt_lock_t {}; +// struct defer_lock_t { explicit defer_lock_t() = default; }; +// struct try_to_lock_t { explicit try_to_lock_t() = default; }; +// struct adopt_lock_t { explicit adopt_lock_t() = default; }; // // constexpr defer_lock_t defer_lock{}; // constexpr try_to_lock_t try_to_lock{}; // constexpr adopt_lock_t adopt_lock{}; #include <mutex> -#include <type_traits> #include "test_macros.h" @@ -33,5 +32,5 @@ int main(int, char**) T2 t2 = std::try_to_lock; ((void)t2); T3 t3 = std::adopt_lock; ((void)t3); - return 0; + return 0; } 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..2b8d09afaae --- /dev/null +++ b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <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..f25450af63b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.fail.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <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..9f855986257 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 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..90b3313eff1 --- /dev/null +++ b/libcxx/test/std/utilities/utility/pairs/pair.piecewise/piecewise_construct_t.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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(); + +// 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..332fe33f41e --- /dev/null +++ b/libcxx/test/std/utilities/utility/pairs/pairs.pair/default.explicit.fail.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// 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 de3730ef3cb..9c53cb8d14b 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(); // This test doesn't pass due to a constexpr bug in GCC 4.9 that fails // to initialize any type without a user provided constructor in a constant |