blob: 25681630a80c3f8d69c6b8720b8fbb8054410947 [file] [log] [blame]
Marshall Clow71e699d2014-02-10 17:40:28 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// [func.require]
11
Dan Albert1d4a1ed2016-05-25 22:36:09 -070012// INVOKE
13#if __cplusplus < 201103L
14int main () {} // no __invoke in C++03
15#else
Eric Fiselier96becae2016-04-29 01:52:57 +000016
Dan Albert1d4a1ed2016-05-25 22:36:09 -070017#include <type_traits>
Marshall Clow71e699d2014-02-10 17:40:28 +000018
19template <typename T, int N>
20struct Array
21{
22 typedef T type[N];
23};
24
25struct Type
26{
27 Array<char, 1>::type& f1();
28 Array<char, 2>::type& f2() const;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070029
Marshall Clow71e699d2014-02-10 17:40:28 +000030 Array<char, 1>::type& g1() &;
31 Array<char, 2>::type& g2() const &;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070032#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clow71e699d2014-02-10 17:40:28 +000033 Array<char, 3>::type& g3() &&;
34 Array<char, 4>::type& g4() const &&;
35#endif
36};
37
38int main()
39{
40 static_assert(sizeof(std::__invoke(&Type::f1, std::declval<Type >())) == 1, "");
41 static_assert(sizeof(std::__invoke(&Type::f2, std::declval<Type const >())) == 2, "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070042
Marshall Clow71e699d2014-02-10 17:40:28 +000043 static_assert(sizeof(std::__invoke(&Type::g1, std::declval<Type &>())) == 1, "");
44 static_assert(sizeof(std::__invoke(&Type::g2, std::declval<Type const &>())) == 2, "");
Dan Albert1d4a1ed2016-05-25 22:36:09 -070045#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clow71e699d2014-02-10 17:40:28 +000046 static_assert(sizeof(std::__invoke(&Type::g3, std::declval<Type &&>())) == 3, "");
47 static_assert(sizeof(std::__invoke(&Type::g4, std::declval<Type const&&>())) == 4, "");
48#endif
49}
Dan Albert1d4a1ed2016-05-25 22:36:09 -070050#endif