xref: /aosp_15_r20/external/clang/test/SemaCXX/ptrtomember.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2*67e74705SXin Li 
3*67e74705SXin Li struct  S {
4*67e74705SXin Li 	int i;
5*67e74705SXin Li 
6*67e74705SXin Li 	int mem(int);
7*67e74705SXin Li };
8*67e74705SXin Li 
foo(int S::* ps,S * s)9*67e74705SXin Li int foo(int S::* ps, S *s)
10*67e74705SXin Li {
11*67e74705SXin Li     return (s->*ps)(1); // expected-error {{called object type 'int' is not a function or function pointer}}
12*67e74705SXin Li }
13*67e74705SXin Li 
14*67e74705SXin Li struct S2 {
15*67e74705SXin Li   int bitfield : 1;
16*67e74705SXin Li };
17*67e74705SXin Li 
18*67e74705SXin Li int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}}
19*67e74705SXin Li 
20*67e74705SXin Li struct S3 {
21*67e74705SXin Li   void m();
22*67e74705SXin Li };
23*67e74705SXin Li 
f3(S3 * p,void (S3::* m)())24*67e74705SXin Li void f3(S3* p, void (S3::*m)()) {
25*67e74705SXin Li     p->*m; // expected-error {{reference to non-static member function must be called}}
26*67e74705SXin Li     (void)(p->*m); // expected-error {{reference to non-static member function must be called}}
27*67e74705SXin Li     (void)(void*)(p->*m); // expected-error {{reference to non-static member function must be called}} expected-error {{cannot cast from type 'void' to pointer type 'void *'}}
28*67e74705SXin Li     (void)reinterpret_cast<void*>(p->*m); // expected-error {{reference to non-static member function must be called}} expected-error {{reinterpret_cast from 'void' to 'void *' is not allowed}}
29*67e74705SXin Li     if (p->*m) {} // expected-error {{reference to non-static member function must be called}} expected-error {{value of type 'void' is not contextually convertible to 'bool'}}
30*67e74705SXin Li     if (!(p->*m)) {} // expected-error {{reference to non-static member function must be called}} expected-error {{invalid argument type 'void' to unary expression}}
31*67e74705SXin Li     if (p->m) {}; // expected-error {{reference to non-static member function must be called}} expected-error {{value of type 'void' is not contextually convertible to 'bool'}}
32*67e74705SXin Li     if (!p->m) {}; // expected-error {{reference to non-static member function must be called}} expected-error {{invalid argument type 'void' to unary expression}}
33*67e74705SXin Li }
34