1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s 2*0a6a1f1dSLionel Sambuc 3*0a6a1f1dSLionel Sambuc #include "Inputs/cuda.h" 4*0a6a1f1dSLionel Sambuc 5*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 6*0a6a1f1dSLionel Sambuc // Test 1: infer default ctor to be host. 7*0a6a1f1dSLionel Sambuc 8*0a6a1f1dSLionel Sambuc struct A1_with_host_ctor { A1_with_host_ctorA1_with_host_ctor9*0a6a1f1dSLionel Sambuc A1_with_host_ctor() {} 10*0a6a1f1dSLionel Sambuc }; 11*0a6a1f1dSLionel Sambuc 12*0a6a1f1dSLionel Sambuc // The implicit default constructor is inferred to be host because it only needs 13*0a6a1f1dSLionel Sambuc // to invoke a single host constructor (A1_with_host_ctor's). So we'll encounter 14*0a6a1f1dSLionel Sambuc // an error when calling it from a __device__ function, but not from a __host__ 15*0a6a1f1dSLionel Sambuc // function. 16*0a6a1f1dSLionel Sambuc struct B1_with_implicit_default_ctor : A1_with_host_ctor { 17*0a6a1f1dSLionel Sambuc }; 18*0a6a1f1dSLionel Sambuc 19*0a6a1f1dSLionel Sambuc // expected-note@-3 {{call to __host__ function from __device__}} 20*0a6a1f1dSLionel Sambuc // expected-note@-4 {{candidate constructor (the implicit copy constructor) not viable}} 21*0a6a1f1dSLionel Sambuc // expected-note@-5 {{candidate constructor (the implicit move constructor) not viable}} 22*0a6a1f1dSLionel Sambuc hostfoo()23*0a6a1f1dSLionel Sambucvoid hostfoo() { 24*0a6a1f1dSLionel Sambuc B1_with_implicit_default_ctor b; 25*0a6a1f1dSLionel Sambuc } 26*0a6a1f1dSLionel Sambuc devicefoo()27*0a6a1f1dSLionel Sambuc__device__ void devicefoo() { 28*0a6a1f1dSLionel Sambuc B1_with_implicit_default_ctor b; // expected-error {{no matching constructor}} 29*0a6a1f1dSLionel Sambuc } 30*0a6a1f1dSLionel Sambuc 31*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 32*0a6a1f1dSLionel Sambuc // Test 2: infer default ctor to be device. 33*0a6a1f1dSLionel Sambuc 34*0a6a1f1dSLionel Sambuc struct A2_with_device_ctor { A2_with_device_ctorA2_with_device_ctor35*0a6a1f1dSLionel Sambuc __device__ A2_with_device_ctor() {} 36*0a6a1f1dSLionel Sambuc }; 37*0a6a1f1dSLionel Sambuc 38*0a6a1f1dSLionel Sambuc struct B2_with_implicit_default_ctor : A2_with_device_ctor { 39*0a6a1f1dSLionel Sambuc }; 40*0a6a1f1dSLionel Sambuc 41*0a6a1f1dSLionel Sambuc // expected-note@-3 {{call to __device__ function from __host__}} 42*0a6a1f1dSLionel Sambuc // expected-note@-4 {{candidate constructor (the implicit copy constructor) not viable}} 43*0a6a1f1dSLionel Sambuc // expected-note@-5 {{candidate constructor (the implicit move constructor) not viable}} 44*0a6a1f1dSLionel Sambuc hostfoo2()45*0a6a1f1dSLionel Sambucvoid hostfoo2() { 46*0a6a1f1dSLionel Sambuc B2_with_implicit_default_ctor b; // expected-error {{no matching constructor}} 47*0a6a1f1dSLionel Sambuc } 48*0a6a1f1dSLionel Sambuc devicefoo2()49*0a6a1f1dSLionel Sambuc__device__ void devicefoo2() { 50*0a6a1f1dSLionel Sambuc B2_with_implicit_default_ctor b; 51*0a6a1f1dSLionel Sambuc } 52*0a6a1f1dSLionel Sambuc 53*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 54*0a6a1f1dSLionel Sambuc // Test 3: infer copy ctor 55*0a6a1f1dSLionel Sambuc 56*0a6a1f1dSLionel Sambuc struct A3_with_device_ctors { A3_with_device_ctorsA3_with_device_ctors57*0a6a1f1dSLionel Sambuc __host__ A3_with_device_ctors() {} A3_with_device_ctorsA3_with_device_ctors58*0a6a1f1dSLionel Sambuc __device__ A3_with_device_ctors(const A3_with_device_ctors&) {} 59*0a6a1f1dSLionel Sambuc }; 60*0a6a1f1dSLionel Sambuc 61*0a6a1f1dSLionel Sambuc struct B3_with_implicit_ctors : A3_with_device_ctors { 62*0a6a1f1dSLionel Sambuc }; 63*0a6a1f1dSLionel Sambuc 64*0a6a1f1dSLionel Sambuc // expected-note@-3 {{copy constructor of 'B3_with_implicit_ctors' is implicitly deleted}} 65*0a6a1f1dSLionel Sambuc hostfoo3()66*0a6a1f1dSLionel Sambucvoid hostfoo3() { 67*0a6a1f1dSLionel Sambuc B3_with_implicit_ctors b; // this is OK because the inferred default ctor 68*0a6a1f1dSLionel Sambuc // here is __host__ 69*0a6a1f1dSLionel Sambuc B3_with_implicit_ctors b2 = b; // expected-error {{call to implicitly-deleted copy constructor}} 70*0a6a1f1dSLionel Sambuc 71*0a6a1f1dSLionel Sambuc } 72*0a6a1f1dSLionel Sambuc 73*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 74*0a6a1f1dSLionel Sambuc // Test 4: infer default ctor from a field, not a base 75*0a6a1f1dSLionel Sambuc 76*0a6a1f1dSLionel Sambuc struct A4_with_host_ctor { A4_with_host_ctorA4_with_host_ctor77*0a6a1f1dSLionel Sambuc A4_with_host_ctor() {} 78*0a6a1f1dSLionel Sambuc }; 79*0a6a1f1dSLionel Sambuc 80*0a6a1f1dSLionel Sambuc struct B4_with_implicit_default_ctor { 81*0a6a1f1dSLionel Sambuc A4_with_host_ctor field; 82*0a6a1f1dSLionel Sambuc }; 83*0a6a1f1dSLionel Sambuc 84*0a6a1f1dSLionel Sambuc // expected-note@-4 {{call to __host__ function from __device__}} 85*0a6a1f1dSLionel Sambuc // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}} 86*0a6a1f1dSLionel Sambuc // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}} 87*0a6a1f1dSLionel Sambuc hostfoo4()88*0a6a1f1dSLionel Sambucvoid hostfoo4() { 89*0a6a1f1dSLionel Sambuc B4_with_implicit_default_ctor b; 90*0a6a1f1dSLionel Sambuc } 91*0a6a1f1dSLionel Sambuc devicefoo4()92*0a6a1f1dSLionel Sambuc__device__ void devicefoo4() { 93*0a6a1f1dSLionel Sambuc B4_with_implicit_default_ctor b; // expected-error {{no matching constructor}} 94*0a6a1f1dSLionel Sambuc } 95*0a6a1f1dSLionel Sambuc 96*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 97*0a6a1f1dSLionel Sambuc // Test 5: copy ctor with non-const param 98*0a6a1f1dSLionel Sambuc 99*0a6a1f1dSLionel Sambuc struct A5_copy_ctor_constness { A5_copy_ctor_constnessA5_copy_ctor_constness100*0a6a1f1dSLionel Sambuc __host__ A5_copy_ctor_constness() {} A5_copy_ctor_constnessA5_copy_ctor_constness101*0a6a1f1dSLionel Sambuc __host__ A5_copy_ctor_constness(A5_copy_ctor_constness&) {} 102*0a6a1f1dSLionel Sambuc }; 103*0a6a1f1dSLionel Sambuc 104*0a6a1f1dSLionel Sambuc struct B5_copy_ctor_constness : A5_copy_ctor_constness { 105*0a6a1f1dSLionel Sambuc }; 106*0a6a1f1dSLionel Sambuc 107*0a6a1f1dSLionel Sambuc // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable: call to __host__ function from __device__ function}} 108*0a6a1f1dSLionel Sambuc // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable}} 109*0a6a1f1dSLionel Sambuc hostfoo5(B5_copy_ctor_constness & b_arg)110*0a6a1f1dSLionel Sambucvoid hostfoo5(B5_copy_ctor_constness& b_arg) { 111*0a6a1f1dSLionel Sambuc B5_copy_ctor_constness b = b_arg; 112*0a6a1f1dSLionel Sambuc } 113*0a6a1f1dSLionel Sambuc devicefoo5(B5_copy_ctor_constness & b_arg)114*0a6a1f1dSLionel Sambuc__device__ void devicefoo5(B5_copy_ctor_constness& b_arg) { 115*0a6a1f1dSLionel Sambuc B5_copy_ctor_constness b = b_arg; // expected-error {{no matching constructor}} 116*0a6a1f1dSLionel Sambuc } 117*0a6a1f1dSLionel Sambuc 118*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 119*0a6a1f1dSLionel Sambuc // Test 6: explicitly defaulted ctor: since they are spelled out, they have 120*0a6a1f1dSLionel Sambuc // a host/device designation explicitly so no inference needs to be done. 121*0a6a1f1dSLionel Sambuc 122*0a6a1f1dSLionel Sambuc struct A6_with_device_ctor { A6_with_device_ctorA6_with_device_ctor123*0a6a1f1dSLionel Sambuc __device__ A6_with_device_ctor() {} 124*0a6a1f1dSLionel Sambuc }; 125*0a6a1f1dSLionel Sambuc 126*0a6a1f1dSLionel Sambuc struct B6_with_defaulted_ctor : A6_with_device_ctor { 127*0a6a1f1dSLionel Sambuc __host__ B6_with_defaulted_ctor() = default; 128*0a6a1f1dSLionel Sambuc }; 129*0a6a1f1dSLionel Sambuc 130*0a6a1f1dSLionel Sambuc // expected-note@-3 {{candidate constructor not viable: call to __host__ function from __device__ function}} 131*0a6a1f1dSLionel Sambuc // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}} 132*0a6a1f1dSLionel Sambuc // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}} 133*0a6a1f1dSLionel Sambuc devicefoo6()134*0a6a1f1dSLionel Sambuc__device__ void devicefoo6() { 135*0a6a1f1dSLionel Sambuc B6_with_defaulted_ctor b; // expected-error {{no matching constructor}} 136*0a6a1f1dSLionel Sambuc } 137*0a6a1f1dSLionel Sambuc 138*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 139*0a6a1f1dSLionel Sambuc // Test 7: copy assignment operator 140*0a6a1f1dSLionel Sambuc 141*0a6a1f1dSLionel Sambuc struct A7_with_copy_assign { A7_with_copy_assignA7_with_copy_assign142*0a6a1f1dSLionel Sambuc A7_with_copy_assign() {} operator =A7_with_copy_assign143*0a6a1f1dSLionel Sambuc __device__ A7_with_copy_assign& operator=(const A7_with_copy_assign&) {} 144*0a6a1f1dSLionel Sambuc }; 145*0a6a1f1dSLionel Sambuc 146*0a6a1f1dSLionel Sambuc struct B7_with_copy_assign : A7_with_copy_assign { 147*0a6a1f1dSLionel Sambuc }; 148*0a6a1f1dSLionel Sambuc 149*0a6a1f1dSLionel Sambuc // expected-note@-3 {{candidate function (the implicit copy assignment operator) not viable: call to __device__ function from __host__ function}} 150*0a6a1f1dSLionel Sambuc // expected-note@-4 {{candidate function (the implicit move assignment operator) not viable: call to __device__ function from __host__ function}} 151*0a6a1f1dSLionel Sambuc hostfoo7()152*0a6a1f1dSLionel Sambucvoid hostfoo7() { 153*0a6a1f1dSLionel Sambuc B7_with_copy_assign b1, b2; 154*0a6a1f1dSLionel Sambuc b1 = b2; // expected-error {{no viable overloaded '='}} 155*0a6a1f1dSLionel Sambuc } 156*0a6a1f1dSLionel Sambuc 157*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------ 158*0a6a1f1dSLionel Sambuc // Test 8: move assignment operator 159*0a6a1f1dSLionel Sambuc 160*0a6a1f1dSLionel Sambuc // definitions for std::move 161*0a6a1f1dSLionel Sambuc namespace std { 162*0a6a1f1dSLionel Sambuc inline namespace foo { 163*0a6a1f1dSLionel Sambuc template <class T> struct remove_reference { typedef T type; }; 164*0a6a1f1dSLionel Sambuc template <class T> struct remove_reference<T&> { typedef T type; }; 165*0a6a1f1dSLionel Sambuc template <class T> struct remove_reference<T&&> { typedef T type; }; 166*0a6a1f1dSLionel Sambuc 167*0a6a1f1dSLionel Sambuc template <class T> typename remove_reference<T>::type&& move(T&& t); 168*0a6a1f1dSLionel Sambuc } 169*0a6a1f1dSLionel Sambuc } 170*0a6a1f1dSLionel Sambuc 171*0a6a1f1dSLionel Sambuc struct A8_with_move_assign { A8_with_move_assignA8_with_move_assign172*0a6a1f1dSLionel Sambuc A8_with_move_assign() {} operator =A8_with_move_assign173*0a6a1f1dSLionel Sambuc __device__ A8_with_move_assign& operator=(A8_with_move_assign&&) {} operator =A8_with_move_assign174*0a6a1f1dSLionel Sambuc __device__ A8_with_move_assign& operator=(const A8_with_move_assign&) {} 175*0a6a1f1dSLionel Sambuc }; 176*0a6a1f1dSLionel Sambuc 177*0a6a1f1dSLionel Sambuc struct B8_with_move_assign : A8_with_move_assign { 178*0a6a1f1dSLionel Sambuc }; 179*0a6a1f1dSLionel Sambuc 180*0a6a1f1dSLionel Sambuc // expected-note@-3 {{candidate function (the implicit copy assignment operator) not viable: call to __device__ function from __host__ function}} 181*0a6a1f1dSLionel Sambuc // expected-note@-4 {{candidate function (the implicit move assignment operator) not viable: call to __device__ function from __host__ function}} 182*0a6a1f1dSLionel Sambuc hostfoo8()183*0a6a1f1dSLionel Sambucvoid hostfoo8() { 184*0a6a1f1dSLionel Sambuc B8_with_move_assign b1, b2; 185*0a6a1f1dSLionel Sambuc b1 = std::move(b2); // expected-error {{no viable overloaded '='}} 186*0a6a1f1dSLionel Sambuc } 187