xref: /llvm-project/clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp (revision f9a14782000e6aa2c4031bc97b20c351a9f281c3)
1// RUN: %clang_cc1 %s -pedantic -ast-dump -verify | FileCheck %s
2
3__constant int g1; // expected-error {{variable in constant address space must be initialized}}
4__constant int g2 = 0;
5
6struct X {
7  int x;
8//CHECK:  CXXConstructorDecl
9//CHECK-NOT:  used
10//CHECK-SAME: X 'void (){{.*}} __generic'
11  X() /*__generic*/ : x(0) {}
12//CHECK: CXXConstructorDecl {{.*}} used X 'void (){{.*}} __private'
13  X() __private : x(0) {}
14//CHECK: CXXConstructorDecl {{.*}} used X 'void (){{.*}} __global'
15  X() __global : x(0) {}
16  constexpr X() __constant : x(0) {}
17  constexpr X(int x) __constant : x(x) {}
18};
19
20__global X gx;
21
22//expected-note@+2{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const __generic Y' for 1st argument}}
23//expected-note@+1{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to '__generic Y' for 1st argument}}
24struct Y {
25  int y;
26  Y() __generic = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
27};
28
29kernel void k() {
30  __constant X cx1;
31  __constant X cx2(1);
32  __local X lx;
33  __private X x;
34
35  __private X tx = X();
36
37  __private Y py;
38  __constant Y cy1; // expected-error{{variable in constant address space must be initialized}}
39  __constant Y cy2(1); // expected-error{{no matching constructor for initialization of '__constant Y'}}
40}
41
42struct Z {
43  int z;
44  // The address space is deduced to be __generic if omitted
45  Z() = default; // expected-note{{previous definition is here}}
46  Z() __generic = default; // expected-error {{constructor cannot be redeclared}}
47
48  Z() __private = default;
49  Z() __local = default;
50  Z() __global = default;
51  // Can't default constexpr constructors
52  constexpr Z() __constant : z(0) {}
53};
54
55struct W {
56  int w;
57  constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor cannot be marked constexpr}}
58};
59