1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
4 int Foo(void *const p
__attribute__((pass_object_size(0))));
6 int OvlFoo(void *const p
__attribute__((pass_object_size(0))));
7 int OvlFoo(void *const p
, int);
10 static int Foo(void *const p
__attribute__((pass_object_size(0))));
11 static int OvlFoo(void *const p
__attribute__((pass_object_size(0))));
12 static int OvlFoo(void *const p
__attribute__((pass_object_size(1)))); // expected-error{{conflicting pass_object_size attributes on parameters}} expected-note@-1{{previous declaration is here}}
13 static int OvlFoo(double *p
);
17 int Foo(void *const p
__attribute__((pass_object_size(0))));
18 int OvlFoo(void *const p
__attribute__((pass_object_size(0))));
19 int OvlFoo(void *const p
, int);
23 int (*A
)(void *) = &Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
24 int (*B
)(void *) = Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
26 int (*C
)(void *) = &OvlFoo
; //expected-error{{address of overloaded function 'OvlFoo' does not match required type 'int (void *)'}} expected-note@6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@7{{candidate function has different number of parameters (expected 1 but has 2)}}
27 int (*D
)(void *) = OvlFoo
; //expected-error{{address of overloaded function 'OvlFoo' does not match required type 'int (void *)'}} expected-note@6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@7{{candidate function has different number of parameters (expected 1 but has 2)}}
29 int (*E
)(void *) = &Statics::Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
30 int (*F
)(void *) = &Statics::OvlFoo
; //expected-error{{address of overloaded function 'OvlFoo' does not match required type 'int (void *)'}} expected-note@11{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@13{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'double *')}}
32 int (*G
)(void *) = &Members::Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
33 int (*H
)(void *) = &Members::OvlFoo
; //expected-error{{address of overloaded function 'OvlFoo' does not match required type 'int (void *)'}} expected-note@18{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@19{{candidate function has different number of parameters (expected 1 but has 2)}}
38 A
= &Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
39 A
= Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
41 A
= &OvlFoo
; //expected-error{{assigning to 'int (*)(void *)' from incompatible type '<overloaded function type>'}} expected-note@6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@7{{candidate function has different number of parameters (expected 1 but has 2)}}
42 A
= OvlFoo
; //expected-error{{assigning to 'int (*)(void *)' from incompatible type '<overloaded function type>'}} expected-note@6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@7{{candidate function has different number of parameters (expected 1 but has 2)}}
44 A
= &Statics::Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
45 A
= &Statics::OvlFoo
; //expected-error{{assigning to 'int (*)(void *)' from incompatible type '<overloaded function type>'}} expected-note@11{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@13{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'double *')}}
47 int (Members::*M
)(void *);
48 M
= &Members::Foo
; //expected-error{{cannot take address of function 'Foo' because parameter 1 has pass_object_size attribute}}
49 M
= &Members::OvlFoo
; //expected-error-re{{assigning to '{{.*}}' from incompatible type '<overloaded function type>'}} expected-note@18{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@19{{candidate function has different number of parameters (expected 1 but has 2)}}
56 int Foo(void *const __attribute__((pass_object_size(0)))) {
60 template <typename T
> struct Bar
{
62 int Foo(void *const __attribute__((pass_object_size(0)))) {
68 int (*A
)(void *) = &Foo
<void*>; //expected-error{{address of overloaded function 'Foo' does not match required type 'int (void *)'}} expected-note@56{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}}
69 int (Bar
<int>::*B
)(void *) = &Bar
<int>::Foo
<double>; //expected-error{{address of overloaded function 'Foo' does not match required type}} expected-note@62{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}}
74 A
= &Foo
<void*>; // expected-error{{assigning to 'int (*)(void *)' from incompatible type '<overloaded function type>'}} expected-note@56{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}}
75 int (Bar
<int>::*B
)(void *) = &Bar
<int>::Foo
<double>; //expected-error{{address of overloaded function 'Foo' does not match required type}} expected-note@62{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}}
77 } // namespace templates
81 virtual void DoIt(void *const p
__attribute__((pass_object_size(0))));
84 struct Bar
: public Foo
{
85 void DoIt(void *const p
__attribute__((pass_object_size(0)))) override
; // OK
88 struct Baz
: public Foo
{
89 void DoIt(void *const p
) override
; //expected-error{{non-virtual member function marked 'override' hides virtual member function}} expected-note@81{{hidden overloaded virtual function 'virt::Foo::DoIt' declared here}}
94 void TakeFn(void (*)(int, void *));
95 void ObjSize(int, void *const __attribute__((pass_object_size(0))));
98 TakeFn(ObjSize
); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
99 TakeFn(&ObjSize
); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
100 TakeFn(*ObjSize
); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
101 TakeFn(*****ObjSize
); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
102 TakeFn(*****&ObjSize
); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
104 void (*P
)(int, void *) = ****ObjSize
; //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
105 P
= ****ObjSize
; //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
107 TakeFn((ObjSize
)); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
108 TakeFn((void*)ObjSize
); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
109 TakeFn((decltype(P
))((void*)ObjSize
)); //expected-error{{cannot take address of function 'ObjSize' because parameter 2 has pass_object_size attribute}}
113 namespace constexpr_support
{
114 constexpr int getObjSizeType() { return 0; }
115 void Foo(void *p
__attribute__((pass_object_size(getObjSizeType()))));
120 (void)+[](void *const p
__attribute__((pass_object_size(0)))) {}; //expected-error-re{{invalid argument type '(lambda at {{.*}})' to unary expression}}
125 // Directly calling an address-of function expression (e.g. in (&foo)(args...))
126 // doesn't go through regular address-of-overload logic. This caused the above
127 // code to generate an ICE.
128 void DirectAddrOf(void *__attribute__((pass_object_size(0))));
129 void DirectAddrOfOvl(void *__attribute__((pass_object_size(0))));
130 void DirectAddrOfOvl(int *);
133 (&DirectAddrOf
)(nullptr); //expected-error{{cannot take address of function 'DirectAddrOf' because parameter 1 has pass_object_size attribute}}
134 (&DirectAddrOfOvl
)((char*)nullptr); //expected-error{{no matching function}} expected-note@129{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@130{{candidate function not viable: no known conversion from 'char *' to 'int *' for 1st argument}}