diff options
author | Hui <hui.xie1990@gmail.com> | 2024-05-29 01:34:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 01:34:29 +0100 |
commit | 2ae3f7c29c1149098827df7edafa761e3e3eb420 (patch) | |
tree | e278c19a4031a21a30989c7c7fb2f99d41e4445e /libcxx/test | |
parent | d868f097053e19e828d7366f5dbb88add16998a2 (diff) | |
download | llvm-2ae3f7c29c1149098827df7edafa761e3e3eb420.zip llvm-2ae3f7c29c1149098827df7edafa761e3e3eb420.tar.gz llvm-2ae3f7c29c1149098827df7edafa761e3e3eb420.tar.bz2 |
[libc++][test] Close LWG3238 and add tests (#93043)
Diffstat (limited to 'libcxx/test')
2 files changed, 25 insertions, 35 deletions
diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.pass.cpp index ef43ab9..381bcda 100644 --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.pass.cpp @@ -118,10 +118,14 @@ int main(int, char**) { // Make sure we fail in a SFINAE-friendly manner when we try to deduce // from a type without a valid call operator. template <typename F, typename = decltype(std::function{std::declval<F>()})> -constexpr bool can_deduce() { return true; } +constexpr bool can_deduce_test(int) { return true; } template <typename F> -constexpr bool can_deduce(...) { return false; } +constexpr bool can_deduce_test(...) { return false; } +template <typename F> +constexpr bool can_deduce = can_deduce_test<F>(0); + +struct valid { int operator()() const; }; struct invalid1 { }; struct invalid2 { template <typename ...Args> @@ -131,6 +135,22 @@ struct invalid3 { void operator()(int); void operator()(long); }; -static_assert(!can_deduce<invalid1>()); -static_assert(!can_deduce<invalid2>()); -static_assert(!can_deduce<invalid3>()); +static_assert( can_deduce<valid>); +static_assert(!can_deduce<invalid1>); +static_assert(!can_deduce<invalid2>); +static_assert(!can_deduce<invalid3>); + + +// LWG 3238. Insufficiently-defined behavior of std::function deduction guides +// https://cplusplus.github.io/LWG/issue3238 +// The deduction guides for std::function do not handle rvalue-ref qualified +// call operators and C-style variadics. It also doesn't deduce from nullptr_t. +// Make sure we stick to the specification. + +struct invalid_rvalue_ref { R operator()() && { return {}; } }; +struct invalid_c_vararg { R operator()(int, ...) { return {}; } }; + +static_assert(!can_deduce<invalid_rvalue_ref>); +static_assert(!can_deduce<invalid_c_vararg>); +static_assert(!can_deduce<std::nullptr_t>); + diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp deleted file mode 100644 index 8a42d3b..0000000 --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -// <functional> - -// template<class F> -// function(F) -> function<see-below>; - -// UNSUPPORTED: c++03, c++11, c++14 - -// The deduction guides for std::function do not handle rvalue-ref qualified -// call operators and C-style variadics. It also doesn't deduce from nullptr_t. -// Make sure we stick to the specification. - -#include <functional> - -struct R { }; -struct f0 { R operator()() && { return {}; } }; -struct f1 { R operator()(int, ...) { return {}; } }; - -void f() { - std::function f = f0{}; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'function'}} - std::function g = f1{}; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'function'}} - std::function h = nullptr; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'function'}} -} |