xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/address-of.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc // PR clang/3175
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc void bar(int*);
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc class c {
7*f4a2713aSLionel Sambuc   int var;
8*f4a2713aSLionel Sambuc   static int svar;
foo()9*f4a2713aSLionel Sambuc   void foo() {
10*f4a2713aSLionel Sambuc     bar(&var);
11*f4a2713aSLionel Sambuc     bar(&svar);
12*f4a2713aSLionel Sambuc   }
13*f4a2713aSLionel Sambuc 
wibble()14*f4a2713aSLionel Sambuc   static void wibble() {
15*f4a2713aSLionel Sambuc     bar(&var); // expected-error{{invalid use of member 'var' in static member function}}
16*f4a2713aSLionel Sambuc     bar(&svar);
17*f4a2713aSLionel Sambuc   }
18*f4a2713aSLionel Sambuc };
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc enum E {
21*f4a2713aSLionel Sambuc   Enumerator
22*f4a2713aSLionel Sambuc };
23*f4a2713aSLionel Sambuc 
test()24*f4a2713aSLionel Sambuc void test() {
25*f4a2713aSLionel Sambuc   (void)&Enumerator; // expected-error{{cannot take the address of an rvalue of type 'E'}}
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc template<int N>
test2()29*f4a2713aSLionel Sambuc void test2() {
30*f4a2713aSLionel Sambuc   (void)&N; // expected-error{{cannot take the address of an rvalue of type 'int'}}
31*f4a2713aSLionel Sambuc }
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc // PR clang/3222
34*f4a2713aSLionel Sambuc void xpto();
35*f4a2713aSLionel Sambuc void (*xyz)(void) = &xpto;
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc struct PR11066 {
38*f4a2713aSLionel Sambuc   static int foo(short);
39*f4a2713aSLionel Sambuc   static int foo(float);
40*f4a2713aSLionel Sambuc   void test();
41*f4a2713aSLionel Sambuc };
42*f4a2713aSLionel Sambuc 
test()43*f4a2713aSLionel Sambuc void PR11066::test() {
44*f4a2713aSLionel Sambuc   int (PR11066::*ptr)(int) = & &PR11066::foo; // expected-error{{extra '&' taking address of overloaded function}}
45*f4a2713aSLionel Sambuc }
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc namespace test3 {
48*f4a2713aSLionel Sambuc   // emit no error
49*f4a2713aSLionel Sambuc   template<typename T> struct S {
50*f4a2713aSLionel Sambuc     virtual void f() = 0;
51*f4a2713aSLionel Sambuc   };
f()52*f4a2713aSLionel Sambuc   template<typename T> void S<T>::f() { T::error; }
53*f4a2713aSLionel Sambuc   void (S<int>::*p)() = &S<int>::f;
54*f4a2713aSLionel Sambuc }
55