]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/function_objects/invoke/3.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function_objects / invoke / 3.cc
CommitLineData
8d9254fc 1// Copyright (C) 2016-2020 Free Software Foundation, Inc.
5f303216
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++17" }
19// { dg-do compile { target c++17 } }
20
21#include <functional>
22
23struct abstract {
24 virtual ~abstract() = 0;
25 void operator()() noexcept;
26};
27
28static_assert( noexcept(std::__invoke(std::declval<abstract>())),
29 "It should be possible to use abstract types with INVOKE" );
30static_assert( noexcept(std::invoke(std::declval<abstract>())),
31 "It should be possible to use abstract types with INVOKE" );
32
33// The std::__invoke_r extension only has a noexcept-specifier for >= C++17.
34static_assert( noexcept(std::__invoke_r<void>(std::declval<abstract>())),
35 "It should be possible to use abstract types with INVOKE<R>" );
36
37struct F {
38 void operator()() &;
39 void operator()() && noexcept;
40 int operator()(int);
41 double* operator()(int, int) noexcept;
42};
43struct D { D(void*); };
44
45static_assert( !noexcept(std::__invoke(std::declval<F&>())), "" );
46static_assert( noexcept(std::__invoke(std::declval<F>())), "" );
47static_assert( !noexcept(std::__invoke(std::declval<F>(), 1)), "" );
48static_assert( noexcept(std::__invoke(std::declval<F>(), 1, 2)), "" );
49
50static_assert( !noexcept(std::invoke(std::declval<F&>())), "" );
51static_assert( noexcept(std::invoke(std::declval<F>())), "" );
52static_assert( !noexcept(std::invoke(std::declval<F>(), 1)), "" );
53static_assert( noexcept(std::invoke(std::declval<F>(), 1, 2)), "" );
54
55static_assert( !noexcept(std::__invoke_r<void>(std::declval<F&>())), "" );
56static_assert( noexcept(std::__invoke_r<void>(std::declval<F>())), "" );
57static_assert( !noexcept(std::__invoke_r<int>(std::declval<F>(), 1)), "" );
58static_assert( !noexcept(std::__invoke_r<void>(std::declval<F>(), 1)), "" );
59static_assert( !noexcept(std::__invoke_r<long>(std::declval<F>(), 1)), "" );
60static_assert( noexcept(std::__invoke_r<void>(std::declval<F>(), 1, 2)), "" );
61static_assert( noexcept(std::__invoke_r<void*>(std::declval<F>(), 1, 2)), "" );
62static_assert( !noexcept(std::__invoke_r<D>(std::declval<F>(), 1, 2)), "" );