1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 template<typename T
, typename U
>
5 static const bool value
= false;
10 static const bool value
= true;
13 typedef int __attribute__((address_space(1))) int_1
;;
14 typedef int __attribute__((address_space(2))) int_2
;;
15 typedef int __attribute__((address_space(1))) *int_1_ptr
;
16 typedef int_2
*int_2_ptr
;
18 // Check that we maintain address spaces through template argument
19 // deduction from a type.
21 struct remove_pointer
{
26 struct remove_pointer
<T
*> {
30 int check_remove0
[is_same
<remove_pointer
<int_1_ptr
>::type
, int_1
>::value
? 1 : -1];
31 int check_remove1
[is_same
<remove_pointer
<int_2_ptr
>::type
, int_2
>::value
? 1 : -1];
32 int check_remove2
[is_same
<remove_pointer
<int_2_ptr
>::type
, int>::value
? -1 : 1];
33 int check_remove3
[is_same
<remove_pointer
<int_2_ptr
>::type
, int_1
>::value
? -1 : 1];
36 struct is_pointer_in_address_space_1
{
37 static const bool value
= false;
41 struct is_pointer_in_address_space_1
<T
__attribute__((address_space(1))) *> {
42 static const bool value
= true;
45 int check_ptr_in_as1
[is_pointer_in_address_space_1
<int_1_ptr
>::value
? 1 : -1];
46 int check_ptr_in_as2
[is_pointer_in_address_space_1
<int_2_ptr
>::value
? -1 : 1];
47 int check_ptr_in_as3
[is_pointer_in_address_space_1
<int*>::value
? -1 : 1];
49 // Check that we maintain address spaces through template argument
50 // deduction for a call.
52 void accept_any_pointer(T
*) {
53 T
*x
= 1; // expected-error{{cannot initialize a variable of type '__attribute__((address_space(1))) int *' with an rvalue of type 'int'}} \
54 // expected-error{{cannot initialize a variable of type '__attribute__((address_space(3))) int *' with an rvalue of type 'int'}}
57 void test_accept_any_pointer(int_1_ptr ip1
, int_2_ptr ip2
) {
58 static __attribute__((address_space(3))) int array
[17];
59 accept_any_pointer(ip1
); // expected-note{{in instantiation of}}
60 accept_any_pointer(array
); // expected-note{{in instantiation of}}
63 template<typename T
> struct identity
{};
66 identity
<T
> accept_arg_in_address_space_1(__attribute__((address_space(1))) T
&ir1
);
69 identity
<T
> accept_any_arg(T
&ir1
);
71 void test_arg_in_address_space_1() {
72 static int __attribute__((address_space(1))) int_1
;
73 identity
<int> ii
= accept_arg_in_address_space_1(int_1
);
74 identity
<int __attribute__((address_space(1)))> ii2
= accept_any_arg(int_1
);
78 template<typename T
> int &order1(__attribute__((address_space(1))) T
&);
79 template<typename T
> float &order1(T
&);
82 static __attribute__((address_space(1))) int i1
;
85 float &fr
= order1(i
);