xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/ptrtomember.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct  S {
4*f4a2713aSLionel Sambuc 	int i;
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc 	int mem(int);
7*f4a2713aSLionel Sambuc };
8*f4a2713aSLionel Sambuc 
foo(int S::* ps,S * s)9*f4a2713aSLionel Sambuc int foo(int S::* ps, S *s)
10*f4a2713aSLionel Sambuc {
11*f4a2713aSLionel Sambuc     return (s->*ps)(1); // expected-error {{called object type 'int' is not a function or function pointer}}
12*f4a2713aSLionel Sambuc }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc struct S2 {
15*f4a2713aSLionel Sambuc   int bitfield : 1;
16*f4a2713aSLionel Sambuc };
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}}
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc struct S3 {
21*f4a2713aSLionel Sambuc   void m();
22*f4a2713aSLionel Sambuc };
23*f4a2713aSLionel Sambuc 
f3(S3 * p,void (S3::* m)())24*f4a2713aSLionel Sambuc void f3(S3* p, void (S3::*m)()) {
25*f4a2713aSLionel Sambuc     p->*m; // expected-error {{reference to non-static member function must be called}}
26*f4a2713aSLionel Sambuc     (void)(p->*m); // expected-error {{reference to non-static member function must be called}}
27*f4a2713aSLionel Sambuc     (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*f4a2713aSLionel Sambuc     (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*f4a2713aSLionel Sambuc     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*f4a2713aSLionel Sambuc     if (!(p->*m)) {} // expected-error {{reference to non-static member function must be called}} expected-error {{invalid argument type 'void' to unary expression}}
31*f4a2713aSLionel Sambuc     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*f4a2713aSLionel Sambuc     if (!p->m) {}; // expected-error {{reference to non-static member function must be called}} expected-error {{invalid argument type 'void' to unary expression}}
33*f4a2713aSLionel Sambuc }
34