xref: /llvm-project/libcxx/test/std/utilities/function.objects/func.memfn/robust_against_adl.pass.cpp (revision 3c8e31e17b85c3d24ade9053d56c1998b4dd28cd)
1*3c8e31e1SArthur O'Dwyer //===----------------------------------------------------------------------===//
2*3c8e31e1SArthur O'Dwyer //
3*3c8e31e1SArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*3c8e31e1SArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
5*3c8e31e1SArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*3c8e31e1SArthur O'Dwyer //
7*3c8e31e1SArthur O'Dwyer //===----------------------------------------------------------------------===//
8*3c8e31e1SArthur O'Dwyer 
9*3c8e31e1SArthur O'Dwyer // <functional>
10*3c8e31e1SArthur O'Dwyer 
11*3c8e31e1SArthur O'Dwyer #include <functional>
12*3c8e31e1SArthur O'Dwyer 
13*3c8e31e1SArthur O'Dwyer #include "test_macros.h"
14*3c8e31e1SArthur O'Dwyer 
15*3c8e31e1SArthur O'Dwyer struct Incomplete;
16*3c8e31e1SArthur O'Dwyer template<class T> struct Holder { T t; };
17*3c8e31e1SArthur O'Dwyer typedef Holder<Incomplete> *Ptr;
18*3c8e31e1SArthur O'Dwyer 
19*3c8e31e1SArthur O'Dwyer struct A {
no_argsA20*3c8e31e1SArthur O'Dwyer     Ptr no_args() const { return nullptr; }
one_argA21*3c8e31e1SArthur O'Dwyer     Ptr one_arg(Ptr p) const { return p; }
one_arg_voidA22*3c8e31e1SArthur O'Dwyer     void one_arg_void(Ptr) const { }
23*3c8e31e1SArthur O'Dwyer };
24*3c8e31e1SArthur O'Dwyer 
main(int,char **)25*3c8e31e1SArthur O'Dwyer int main(int, char**)
26*3c8e31e1SArthur O'Dwyer {
27*3c8e31e1SArthur O'Dwyer     A a;
28*3c8e31e1SArthur O'Dwyer     A *pa = &a;
29*3c8e31e1SArthur O'Dwyer     const A *cpa = &a;
30*3c8e31e1SArthur O'Dwyer     Ptr x = nullptr;
31*3c8e31e1SArthur O'Dwyer     const Ptr cx = nullptr;
32*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::no_args)(a);
33*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::no_args)(pa);
34*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::no_args)(*cpa);
35*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::no_args)(cpa);
36*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(a, x);
37*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(pa, x);
38*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(a, cx);
39*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(pa, cx);
40*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(*cpa, x);
41*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(cpa, x);
42*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(*cpa, cx);
43*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg)(cpa, cx);
44*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(a, x);
45*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(pa, x);
46*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(a, cx);
47*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(pa, cx);
48*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(*cpa, x);
49*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(cpa, x);
50*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(*cpa, cx);
51*3c8e31e1SArthur O'Dwyer     std::mem_fn(&A::one_arg_void)(cpa, cx);
52*3c8e31e1SArthur O'Dwyer     return 0;
53*3c8e31e1SArthur O'Dwyer }
54