Fixes https://github.com/llvm/llvm-project/issues/104307 This patch implements LWG3476 by removing the incorrect decay-copy in std::async. The decay-copy was being applied twice, once explicitly via _LIBCPP_AUTO_CAST and once in __async_func's tuple constructor. (https://github.com/llvm/llvm-project/issues/143828) It also adds static_assert mandates to std::thread and std::async (which were already implicitly enforced) and expands test coverage.
97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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: no-threads
|
|
// REQUIRES: std-at-least-c++20
|
|
|
|
// <jthread>
|
|
|
|
// class jthread
|
|
|
|
// template<class F, class... Args>
|
|
// explicit jthread(F&& f, Args&&... args);
|
|
|
|
#include <thread>
|
|
|
|
void test() {
|
|
{ // Mandates: is_constructible_v<decay_t<F>, F>
|
|
struct F {
|
|
F() = default;
|
|
F(const F&) = delete;
|
|
F(F&&) = default;
|
|
|
|
void operator()() {}
|
|
};
|
|
|
|
F f;
|
|
std::jthread t(f);
|
|
// expected-error@*:* 2 {{static assertion failed}}
|
|
// expected-error@*:* 0-2 {{call to deleted constructor}}
|
|
// expected-error@*:* {{no matching constructor for initialization}}
|
|
}
|
|
|
|
{ // Mandates: is_constructible_v<decay_t<F>, F>
|
|
struct F {
|
|
F() = default;
|
|
F(const F&) = default;
|
|
F(F&&) = delete;
|
|
|
|
void operator()() {}
|
|
};
|
|
|
|
std::jthread t(F{});
|
|
// expected-error@*:* 2 {{static assertion failed}}
|
|
// expected-error@*:* 0-2 {{call to deleted constructor}}
|
|
// expected-error@*:* {{no matching constructor for initialization}}
|
|
}
|
|
|
|
{ // Mandates: (is_constructible_v<decay_t<Args>, Args> && ...)
|
|
struct Arg {
|
|
Arg() = default;
|
|
Arg(const Arg&) = delete;
|
|
Arg(Arg&&) = default;
|
|
};
|
|
|
|
struct F {
|
|
void operator()(const Arg&) const {}
|
|
};
|
|
|
|
Arg arg;
|
|
std::jthread t(F{}, arg);
|
|
// expected-error@*:* 2 {{static assertion failed}}
|
|
// expected-error@*:* 0-1 {{call to deleted constructor}}
|
|
// expected-error@*:* {{no matching constructor for initialization}}
|
|
}
|
|
|
|
{ // Mandates: (is_constructible_v<decay_t<Args>, Args> && ...)
|
|
struct Arg {
|
|
Arg() = default;
|
|
Arg(const Arg&) = default;
|
|
Arg(Arg&&) = delete;
|
|
};
|
|
|
|
struct F {
|
|
void operator()(const Arg&) const {}
|
|
};
|
|
|
|
std::jthread t(F{}, Arg{});
|
|
// expected-error@*:* 2 {{static assertion failed}}
|
|
// expected-error@*:* 0-1 {{call to deleted constructor}}
|
|
// expected-error@*:* {{no matching constructor for initialization}}
|
|
}
|
|
|
|
{ // Mandates: is_invocable_v<decay_t<F>, decay_t<Args>...>
|
|
struct F {};
|
|
|
|
std::jthread t(F{});
|
|
// expected-error@*:* 2 {{static assertion failed}}
|
|
// expected-error@*:* 0-1 {{no matching function for call to '__invoke'}}
|
|
// expected-error@*:* 0-1 {{attempt to use a deleted function}}
|
|
}
|
|
}
|