Debian Codegraph @

clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp

raw
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
6 struct 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}}
24 struct Y {
25 int y;
26 Y() __generic = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
27 };
28
29 kernel 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
42 struct 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
55 struct W {
56 int w;
57 constexpr W() __constant = default; // expected-error {{defaulted definition of default constructor cannot be marked constexpr}}
58 };