| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: no-threads |
| 10 | // UNSUPPORTED: c++03, c++11, c++14 |
| 11 | |
| 12 | // checks that CTAD works properly |
| 13 | |
| 14 | #include <future> |
| 15 | #include <type_traits> |
| 16 | |
| 17 | int func(char*); |
| 18 | static_assert(std::is_same_v<decltype(std::packaged_task{func}), std::packaged_task<int(char*)>>); |
| 19 | |
| 20 | int funcn(char*) noexcept; |
| 21 | static_assert(std::is_same_v<decltype(std::packaged_task{funcn}), std::packaged_task<int(char*)>>); |
| 22 | |
| 23 | template <bool Noexcept> |
| 24 | struct Callable { |
| 25 | int operator()(char*) noexcept(Noexcept); |
| 26 | }; |
| 27 | static_assert(std::is_same_v<decltype(std::packaged_task{Callable<true>{}}), std::packaged_task<int(char*)>>); |
| 28 | static_assert(std::is_same_v<decltype(std::packaged_task{Callable<false>{}}), std::packaged_task<int(char*)>>); |
| 29 | |
| 30 | template <bool Noexcept> |
| 31 | struct CallableC { |
| 32 | int operator()(char*) const noexcept(Noexcept); |
| 33 | }; |
| 34 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableC<true>{}}), std::packaged_task<int(char*)>>); |
| 35 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableC<false>{}}), std::packaged_task<int(char*)>>); |
| 36 | |
| 37 | template <bool Noexcept> |
| 38 | struct CallableV { |
| 39 | int operator()(char*) const noexcept(Noexcept); |
| 40 | }; |
| 41 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableV<true>{}}), std::packaged_task<int(char*)>>); |
| 42 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableV<false>{}}), std::packaged_task<int(char*)>>); |
| 43 | |
| 44 | template <bool Noexcept> |
| 45 | struct CallableCV { |
| 46 | int operator()(char*) const volatile noexcept(Noexcept); |
| 47 | }; |
| 48 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableCV<true>{}}), std::packaged_task<int(char*)>>); |
| 49 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableCV<false>{}}), std::packaged_task<int(char*)>>); |
| 50 | |
| 51 | template <bool Noexcept> |
| 52 | struct CallableL { |
| 53 | int operator()(char*) & noexcept(Noexcept); |
| 54 | }; |
| 55 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableL<true>{}}), std::packaged_task<int(char*)>>); |
| 56 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableL<false>{}}), std::packaged_task<int(char*)>>); |
| 57 | |
| 58 | template <bool Noexcept> |
| 59 | struct CallableCL { |
| 60 | int operator()(char*) const & noexcept(Noexcept); |
| 61 | }; |
| 62 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableCL<true>{}}), std::packaged_task<int(char*)>>); |
| 63 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableCL<false>{}}), std::packaged_task<int(char*)>>); |
| 64 | |
| 65 | template <bool Noexcept> |
| 66 | struct CallableVL { |
| 67 | int operator()(char*) const noexcept(Noexcept); |
| 68 | }; |
| 69 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableVL<true>{}}), std::packaged_task<int(char*)>>); |
| 70 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableVL<false>{}}), std::packaged_task<int(char*)>>); |
| 71 | |
| 72 | template <bool Noexcept> |
| 73 | struct CallableCVL { |
| 74 | int operator()(char*) const volatile & noexcept(Noexcept); |
| 75 | }; |
| 76 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableCVL<true>{}}), std::packaged_task<int(char*)>>); |
| 77 | static_assert(std::is_same_v<decltype(std::packaged_task{CallableCVL<false>{}}), std::packaged_task<int(char*)>>); |
| 78 | |