From beb6efb42eca21ef5b9d1cf616558dfb991186c7 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 1 Apr 2019 19:53:44 +0000 Subject: [PATCH] [libcxx] Make sure reference_wrapper works with incomplete types Summary: Completes P0357R3, which was merged into the C++20 Working Draft in San Diego. Reviewers: EricWF, mclow.lists Subscribers: christof, jkorous, dexonsmith, libcxx-commits Differential Revision: https://reviews.llvm.org/D54722 llvm-svn: 357423 --- .../refwrap/refwrap.const/ctor.incomplete.pass.cpp | 41 +++++++++++++++++++++ .../refwrap.helpers/cref.incomplete.pass.cpp | 42 ++++++++++++++++++++++ .../refwrap.helpers/ref.incomplete.pass.cpp | 42 ++++++++++++++++++++++ .../refwrap.invoke/invoke.incomplete.fail.cpp | 37 +++++++++++++++++++ libcxx/www/cxx2a_status.html | 2 +- 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/ctor.incomplete.pass.cpp create mode 100644 libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref.incomplete.pass.cpp create mode 100644 libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref.incomplete.pass.cpp create mode 100644 libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.incomplete.fail.cpp diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/ctor.incomplete.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/ctor.incomplete.pass.cpp new file mode 100644 index 0000000..d26e4cb --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.const/ctor.incomplete.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11, c++14, c++17 + +// +// +// reference_wrapper +// +// where T is an incomplete type (since C++20) + + +#include +#include + + +struct Foo; + +Foo& get_foo(); + +void test() { + Foo& foo = get_foo(); + std::reference_wrapper ref{foo}; + assert(&ref.get() == &foo); +} + +struct Foo { }; + +Foo& get_foo() { + static Foo foo; + return foo; +} + +int main() { + test(); +} diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref.incomplete.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref.incomplete.pass.cpp new file mode 100644 index 0000000..4aad297 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref.incomplete.pass.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, c++11, c++14, c++17 + +// +// +// reference_wrapper +// +// template reference_wrapper cref(const T& t); +// +// where T is an incomplete type (since C++20) + +#include +#include + + +struct Foo; + +Foo& get_foo(); + +void test() { + Foo const& foo = get_foo(); + std::reference_wrapper ref = std::cref(foo); + assert(&ref.get() == &foo); +} + +struct Foo { }; + +Foo& get_foo() { + static Foo foo; + return foo; +} + +int main() { + test(); +} diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref.incomplete.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref.incomplete.pass.cpp new file mode 100644 index 0000000..d5c26b2 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref.incomplete.pass.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, c++11, c++14, c++17 + +// +// +// reference_wrapper +// +// template reference_wrapper ref(T& t); +// +// where T is an incomplete type (since C++20) + +#include +#include + + +struct Foo; + +Foo& get_foo(); + +void test() { + Foo& foo = get_foo(); + std::reference_wrapper ref = std::ref(foo); + assert(&ref.get() == &foo); +} + +struct Foo { }; + +Foo& get_foo() { + static Foo foo; + return foo; +} + +int main() { + test(); +} diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.incomplete.fail.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.incomplete.fail.cpp new file mode 100644 index 0000000..255e802 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke.incomplete.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11, c++14, c++17 + +// +// +// reference_wrapper +// +// template +// std::invoke_result_t +// operator()(ArgTypes&&... args) const; +// +// Requires T to be a complete type (since C++20). + +#include + + +struct Foo; +Foo& get_foo(); + +void test() { + std::reference_wrapper ref = get_foo(); + ref(0); // incomplete at the point of call +} + +struct Foo { void operator()(int) const { } }; +Foo& get_foo() { static Foo foo; return foo; } + +int main() { + test(); +} diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html index 4489399..0adc0e1 100644 --- a/libcxx/www/cxx2a_status.html +++ b/libcxx/www/cxx2a_status.html @@ -109,7 +109,7 @@ P0318R1LWGunwrap_ref_decay and unwrap_referenceSan DiegoComplete8.0 P0356R5LWGSimplified partial function applicationSan Diego - P0357R3LWGreference_wrapper for incomplete typesSan Diego + P0357R3LWGreference_wrapper for incomplete typesSan DiegoComplete8.0 P0482R6CWGchar8_t: A type for UTF-8 characters and stringsSan Diego P0487R1LWGFixing operator>>(basic_istream&, CharT*) (LWG 2499)San DiegoComplete8.0 P0591R4LWGUtility functions to implement uses-allocator constructionSan Diego -- 2.7.4