blob: 26e72241841461afde571e7e016ebc83ad3f7542 [file] [log] [blame]
Douglas Gregora459cc22011-04-27 23:34:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3template<typename T, typename U>
4struct is_same {
5 static const bool value = false;
6};
7
8template<typename T>
9struct is_same<T, T> {
10 static const bool value = true;
11};
12
13typedef int __attribute__((address_space(1))) int_1;;
14typedef int __attribute__((address_space(2))) int_2;;
15typedef int __attribute__((address_space(1))) *int_1_ptr;
16typedef int_2 *int_2_ptr;
17
18// Check that we maintain address spaces through template argument
19// deduction from a type.
20template<typename T>
21struct remove_pointer {
22 typedef T type;
23};
24
25template<typename T>
26struct remove_pointer<T *> {
27 typedef T type;
28};
29
30int check_remove0[is_same<remove_pointer<int_1_ptr>::type, int_1>::value? 1 : -1];
31int check_remove1[is_same<remove_pointer<int_2_ptr>::type, int_2>::value? 1 : -1];
32int check_remove2[is_same<remove_pointer<int_2_ptr>::type, int>::value? -1 : 1];
33int check_remove3[is_same<remove_pointer<int_2_ptr>::type, int_1>::value? -1 : 1];
34
35// Check that we maintain address spaces through template argument
36// deduction for a call.
37template<typename T>
38void accept_any_pointer(T*) {
39 T *x = 1; // expected-error{{cannot initialize a variable of type '__attribute__((address_space(1))) int *' with an rvalue of type 'int'}} \
40 // expected-error{{cannot initialize a variable of type '__attribute__((address_space(3))) int *' with an rvalue of type 'int'}}
41}
42
43void test_accept_any_pointer(int_1_ptr ip1, int_2_ptr ip2) {
44 static __attribute__((address_space(3))) int array[17];
45 accept_any_pointer(ip1); // expected-note{{in instantiation of}}
46 accept_any_pointer(array); // expected-note{{in instantiation of}}
47}
48