1*67e74705SXin Li // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s 2*67e74705SXin Li 3*67e74705SXin Li #include "Inputs/cuda.h" 4*67e74705SXin Li 5*67e74705SXin Li //------------------------------------------------------------------------------ 6*67e74705SXin Li // Test 1: collision between two bases 7*67e74705SXin Li 8*67e74705SXin Li struct A1_with_host_ctor { A1_with_host_ctorA1_with_host_ctor9*67e74705SXin Li A1_with_host_ctor() {} 10*67e74705SXin Li }; 11*67e74705SXin Li 12*67e74705SXin Li struct B1_with_device_ctor { B1_with_device_ctorB1_with_device_ctor13*67e74705SXin Li __device__ B1_with_device_ctor() {} 14*67e74705SXin Li }; 15*67e74705SXin Li 16*67e74705SXin Li struct C1_with_collision : A1_with_host_ctor, B1_with_device_ctor { 17*67e74705SXin Li }; 18*67e74705SXin Li 19*67e74705SXin Li // expected-note@-3 {{candidate constructor (the implicit default constructor) not viable}} 20*67e74705SXin Li // expected-note@-4 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}} 21*67e74705SXin Li // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}} 22*67e74705SXin Li // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}} 23*67e74705SXin Li hostfoo1()24*67e74705SXin Livoid hostfoo1() { 25*67e74705SXin Li C1_with_collision c; // expected-error {{no matching constructor}} 26*67e74705SXin Li } 27*67e74705SXin Li 28*67e74705SXin Li //------------------------------------------------------------------------------ 29*67e74705SXin Li // Test 2: collision between two fields 30*67e74705SXin Li 31*67e74705SXin Li struct C2_with_collision { 32*67e74705SXin Li A1_with_host_ctor aa; 33*67e74705SXin Li B1_with_device_ctor bb; 34*67e74705SXin Li }; 35*67e74705SXin Li 36*67e74705SXin Li // expected-note@-5 {{candidate constructor (the implicit default constructor}} not viable 37*67e74705SXin Li // expected-note@-6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}} 38*67e74705SXin Li // expected-note@-7 {{candidate constructor (the implicit copy constructor}} not viable 39*67e74705SXin Li // expected-note@-8 {{candidate constructor (the implicit move constructor}} not viable 40*67e74705SXin Li hostfoo2()41*67e74705SXin Livoid hostfoo2() { 42*67e74705SXin Li C2_with_collision c; // expected-error {{no matching constructor}} 43*67e74705SXin Li } 44*67e74705SXin Li 45*67e74705SXin Li //------------------------------------------------------------------------------ 46*67e74705SXin Li // Test 3: collision between a field and a base 47*67e74705SXin Li 48*67e74705SXin Li struct C3_with_collision : A1_with_host_ctor { 49*67e74705SXin Li B1_with_device_ctor bb; 50*67e74705SXin Li }; 51*67e74705SXin Li 52*67e74705SXin Li // expected-note@-4 {{candidate constructor (the implicit default constructor}} not viable 53*67e74705SXin Li // expected-note@-5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}} 54*67e74705SXin Li // expected-note@-6 {{candidate constructor (the implicit copy constructor}} not viable 55*67e74705SXin Li // expected-note@-7 {{candidate constructor (the implicit move constructor}} not viable 56*67e74705SXin Li hostfoo3()57*67e74705SXin Livoid hostfoo3() { 58*67e74705SXin Li C3_with_collision c; // expected-error {{no matching constructor}} 59*67e74705SXin Li } 60*67e74705SXin Li 61*67e74705SXin Li //------------------------------------------------------------------------------ 62*67e74705SXin Li // Test 4: collision on resolving a copy ctor 63*67e74705SXin Li 64*67e74705SXin Li struct A4_with_host_copy_ctor { A4_with_host_copy_ctorA4_with_host_copy_ctor65*67e74705SXin Li A4_with_host_copy_ctor() {} A4_with_host_copy_ctorA4_with_host_copy_ctor66*67e74705SXin Li A4_with_host_copy_ctor(const A4_with_host_copy_ctor&) {} 67*67e74705SXin Li }; 68*67e74705SXin Li 69*67e74705SXin Li struct B4_with_device_copy_ctor { B4_with_device_copy_ctorB4_with_device_copy_ctor70*67e74705SXin Li B4_with_device_copy_ctor() {} B4_with_device_copy_ctorB4_with_device_copy_ctor71*67e74705SXin Li __device__ B4_with_device_copy_ctor(const B4_with_device_copy_ctor&) {} 72*67e74705SXin Li }; 73*67e74705SXin Li 74*67e74705SXin Li struct C4_with_collision : A4_with_host_copy_ctor, B4_with_device_copy_ctor { 75*67e74705SXin Li }; 76*67e74705SXin Li 77*67e74705SXin Li // expected-note@-3 {{copy constructor of 'C4_with_collision' is implicitly deleted because base class 'B4_with_device_copy_ctor' has no copy constructor}} 78*67e74705SXin Li hostfoo4()79*67e74705SXin Livoid hostfoo4() { 80*67e74705SXin Li C4_with_collision c; 81*67e74705SXin Li C4_with_collision c2 = c; // expected-error {{call to implicitly-deleted copy constructor of 'C4_with_collision'}} 82*67e74705SXin Li } 83*67e74705SXin Li 84*67e74705SXin Li //------------------------------------------------------------------------------ 85*67e74705SXin Li // Test 5: collision on resolving a move ctor 86*67e74705SXin Li 87*67e74705SXin Li struct A5_with_host_move_ctor { A5_with_host_move_ctorA5_with_host_move_ctor88*67e74705SXin Li A5_with_host_move_ctor() {} A5_with_host_move_ctorA5_with_host_move_ctor89*67e74705SXin Li A5_with_host_move_ctor(A5_with_host_move_ctor&&) {} 90*67e74705SXin Li // expected-note@-1 {{copy constructor is implicitly deleted because 'A5_with_host_move_ctor' has a user-declared move constructor}} 91*67e74705SXin Li }; 92*67e74705SXin Li 93*67e74705SXin Li struct B5_with_device_move_ctor { B5_with_device_move_ctorB5_with_device_move_ctor94*67e74705SXin Li B5_with_device_move_ctor() {} B5_with_device_move_ctorB5_with_device_move_ctor95*67e74705SXin Li __device__ B5_with_device_move_ctor(B5_with_device_move_ctor&&) {} 96*67e74705SXin Li }; 97*67e74705SXin Li 98*67e74705SXin Li struct C5_with_collision : A5_with_host_move_ctor, B5_with_device_move_ctor { 99*67e74705SXin Li }; 100*67e74705SXin Li // expected-note@-2 {{deleted}} 101*67e74705SXin Li hostfoo5()102*67e74705SXin Livoid hostfoo5() { 103*67e74705SXin Li C5_with_collision c; 104*67e74705SXin Li // What happens here: 105*67e74705SXin Li // This tries to find the move ctor. Since the move ctor is deleted due to 106*67e74705SXin Li // collision, it then looks for a copy ctor. But copy ctors are implicitly 107*67e74705SXin Li // deleted when move ctors are declared explicitly. 108*67e74705SXin Li C5_with_collision c2(static_cast<C5_with_collision&&>(c)); // expected-error {{call to implicitly-deleted}} 109*67e74705SXin Li } 110