xref: /aosp_15_r20/external/clang/test/CXX/expr/expr.mptr.oper/p6-0x.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li struct X { };
4*67e74705SXin Li 
5*67e74705SXin Li template<typename T> T& lvalue();
6*67e74705SXin Li template<typename T> T&& xvalue();
7*67e74705SXin Li template<typename T> T prvalue();
8*67e74705SXin Li 
9*67e74705SXin Li // In a .* expression whose object expression is an rvalue, the
10*67e74705SXin Li // program is ill-formed if the second operand is a pointer to member
11*67e74705SXin Li // function with ref-qualifier &. In a ->* expression or in a .*
12*67e74705SXin Li // expression whose object expression is an lvalue, the program is
13*67e74705SXin Li // ill-formed if the second operand is a pointer to member function
14*67e74705SXin Li // with ref-qualifier &&.
test(X * xp,int (X::* pmf)(int),int (X::* l_pmf)(int)&,int (X::* r_pmf)(int)&&)15*67e74705SXin Li void test(X *xp, int (X::*pmf)(int), int (X::*l_pmf)(int) &,
16*67e74705SXin Li           int (X::*r_pmf)(int) &&) {
17*67e74705SXin Li   // No ref-qualifier.
18*67e74705SXin Li   (lvalue<X>().*pmf)(17);
19*67e74705SXin Li   (xvalue<X>().*pmf)(17);
20*67e74705SXin Li   (prvalue<X>().*pmf)(17);
21*67e74705SXin Li   (xp->*pmf)(17);
22*67e74705SXin Li 
23*67e74705SXin Li   // Lvalue ref-qualifier.
24*67e74705SXin Li   (lvalue<X>().*l_pmf)(17);
25*67e74705SXin Li   (xvalue<X>().*l_pmf)(17); // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &' can only be called on an lvalue}}
26*67e74705SXin Li   (prvalue<X>().*l_pmf)(17); // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &' can only be called on an lvalue}}
27*67e74705SXin Li   (xp->*l_pmf)(17);
28*67e74705SXin Li 
29*67e74705SXin Li   // Rvalue ref-qualifier.
30*67e74705SXin Li   (lvalue<X>().*r_pmf)(17); // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &&' can only be called on an rvalue}}
31*67e74705SXin Li   (xvalue<X>().*r_pmf)(17);
32*67e74705SXin Li   (prvalue<X>().*r_pmf)(17);
33*67e74705SXin Li   (xp->*r_pmf)(17);  // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &&' can only be called on an rvalue}}
34*67e74705SXin Li }
35