xref: /llvm-project/clang/test/SemaOpenCLCXX/address-space-templates.clcpp (revision 6e46f0b628308ba39feb13872cb21166b857dfdb)
1//RUN: %clang_cc1 %s -pedantic -verify -ast-dump  | FileCheck %s
2
3template <typename T>
4struct S {
5  T a;        // expected-error{{field may not be qualified with an address space}}
6  T f1();     // we ignore address space on a return types.
7  void f2(T); // expected-error{{parameter may not be qualified with an address space}}
8};
9
10template <typename T>
11T foo1(__global T *i) { // expected-note{{candidate template ignored: substitution failure [with T = __local int]: conflicting address space qualifiers are provided between types '__global T' and '__local int'}}
12  return *i;
13}
14
15template <typename T>
16T *foo2(T *i) {
17  return i;
18}
19
20template <typename T>
21void foo3() {
22  __private T ii; // expected-error{{conflicting address space qualifiers are provided between types '__private T' and '__global int'}}
23}
24
25template <class _Tp> struct remove_reference         { typedef _Tp type; };
26template <class _Tp> struct remove_reference<_Tp &>  { typedef _Tp type; };
27template <class _Tp> struct as_pointer {
28    typedef typename remove_reference<_Tp>::type* type;
29};
30
31// Check address space deduction in template parameter deduction.
32struct rep {
33  // When there is no address space on a reference use __generic.
34  // CHECK: |-CXXConstructorDecl {{.*}} rep 'void (const __generic rep &__private){{.*}} __generic'
35  template<class U, class = typename as_pointer<U>::type>
36  rep(U&& v) {}
37};
38
39struct rep_outer : private rep {
40  rep_outer()
41    : rep(0) {}
42};
43
44
45template<class T, class F>
46void foo4(T t, F f){
47  f(t);
48}
49
50void bar() {
51  S<const __global int> sintgl; // expected-note{{in instantiation of template class 'S<const __global int>' requested here}}
52
53  foo1<__local int>(1); // expected-error{{no matching function for call to 'foo1'}}
54  foo2<__global int>(0);
55  foo3<__global int>(); // expected-note{{in instantiation of function template specialization 'foo3<__global int>' requested here}}
56
57  rep_outer r;
58  int i;
59  // Preserve the address space of the type in forwarding reference.
60  // CHECK: CXXMethodDecl {{.*}} operator() 'void (__private int &__private){{.*}} const __generic'
61  foo4(i, [](auto&& x){;});
62}
63