[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / SemaCUDA / implicit-member-target-collision-cxx11.cu
blob06015ed0d6d8edcb56884ca2e15c3ca777af0823
1 // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
3 #include "Inputs/cuda.h"
5 //------------------------------------------------------------------------------
6 // Test 1: collision between two bases
8 struct A1_with_host_ctor {
9   A1_with_host_ctor() {}
12 struct B1_with_device_ctor {
13   __device__ B1_with_device_ctor() {}
16 struct C1_with_collision : A1_with_host_ctor, B1_with_device_ctor {
19 // expected-note@-3 {{candidate constructor (the implicit default constructor) not viable}}
20 // expected-note@-4 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
21 // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
22 // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
24 void hostfoo1() {
25   C1_with_collision c; // expected-error {{no matching constructor}}
28 //------------------------------------------------------------------------------
29 // Test 2: collision between two fields
31 struct C2_with_collision {
32   A1_with_host_ctor aa;
33   B1_with_device_ctor bb;
36 // expected-note@-5 {{candidate constructor (the implicit default constructor}} not viable
37 // expected-note@-6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
38 // expected-note@-7 {{candidate constructor (the implicit copy constructor}} not viable
39 // expected-note@-8 {{candidate constructor (the implicit move constructor}} not viable
41 void hostfoo2() {
42   C2_with_collision c; // expected-error {{no matching constructor}}
45 //------------------------------------------------------------------------------
46 // Test 3: collision between a field and a base
48 struct C3_with_collision : A1_with_host_ctor {
49   B1_with_device_ctor bb;
52 // expected-note@-4 {{candidate constructor (the implicit default constructor}} not viable
53 // expected-note@-5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
54 // expected-note@-6 {{candidate constructor (the implicit copy constructor}} not viable
55 // expected-note@-7 {{candidate constructor (the implicit move constructor}} not viable
57 void hostfoo3() {
58   C3_with_collision c; // expected-error {{no matching constructor}}
61 //------------------------------------------------------------------------------
62 // Test 4: collision on resolving a copy ctor
64 struct A4_with_host_copy_ctor {
65   A4_with_host_copy_ctor() {}
66   A4_with_host_copy_ctor(const A4_with_host_copy_ctor&) {}
69 struct B4_with_device_copy_ctor {
70   B4_with_device_copy_ctor() {}
71   __device__ B4_with_device_copy_ctor(const B4_with_device_copy_ctor&) {}
74 struct C4_with_collision : A4_with_host_copy_ctor, B4_with_device_copy_ctor {
77 // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable: call to invalid function from __host__ function}}
78 // expected-note@-4 {{implicit copy constructor inferred target collision: call to both __host__ and __device__ members}}
79 // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
81 void hostfoo4() {
82   C4_with_collision c;
83   C4_with_collision c2 = c; // expected-error {{no matching constructor for initialization of 'C4_with_collision'}}
86 //------------------------------------------------------------------------------
87 // Test 5: collision on resolving a move ctor
89 struct A5_with_host_move_ctor {
90   A5_with_host_move_ctor() {}
91   A5_with_host_move_ctor(A5_with_host_move_ctor&&) {}
92 // expected-note@-1 {{copy constructor is implicitly deleted because 'A5_with_host_move_ctor' has a user-declared move constructor}}
95 struct B5_with_device_move_ctor {
96   B5_with_device_move_ctor() {}
97   __device__ B5_with_device_move_ctor(B5_with_device_move_ctor&&) {}
100 struct C5_with_collision : A5_with_host_move_ctor, B5_with_device_move_ctor {
102 // expected-note@-2 {{deleted}}
104 void hostfoo5() {
105   C5_with_collision c;
106   // What happens here:
107   // This tries to find the move ctor. Since the move ctor is deleted due to
108   // collision, it then looks for a copy ctor. But copy ctors are implicitly
109   // deleted when move ctors are declared explicitly.
110   C5_with_collision c2(static_cast<C5_with_collision&&>(c)); // expected-error {{call to implicitly-deleted}}