llvm-project
44 строки · 1.1 Кб
1// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-linux-unknown -fsyntax-only -o - -verify
2
3#include "Inputs/cuda.h"
4
5struct A {
6int a;
7__device__ A() { a = 1; }
8__device__ ~A() { a = 2; }
9};
10
11// This can be a global var since ctor/dtors of data members are not called.
12union B {
13A a;
14__device__ B() {}
15__device__ ~B() {}
16};
17
18// This cannot be a global var since it has a dynamic ctor.
19union C {
20A a;
21__device__ C() { a.a = 3; }
22__device__ ~C() {}
23};
24
25// This cannot be a global var since it has a dynamic dtor.
26union D {
27A a;
28__device__ D() { }
29__device__ ~D() { a.a = 4; }
30};
31
32__device__ B b;
33__device__ C c;
34// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
35__device__ D d;
36// expected-error@-1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
37
38__device__ void foo() {
39__shared__ B b;
40__shared__ C c;
41// expected-error@-1 {{initialization is not supported for __shared__ variables}}
42__shared__ D d;
43// expected-error@-1 {{initialization is not supported for __shared__ variables}}
44}
45