implicit-member-target-inherited.cu 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -Wno-defaulted-function-deleted
  2. #include "Inputs/cuda.h"
  3. //------------------------------------------------------------------------------
  4. // Test 1: infer inherited default ctor to be host.
  5. struct A1_with_host_ctor {
  6. A1_with_host_ctor() {}
  7. };
  8. // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
  9. // expected-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
  10. // The inherited default constructor is inferred to be host, so we'll encounter
  11. // an error when calling it from a __device__ function, but not from a __host__
  12. // function.
  13. struct B1_with_implicit_default_ctor : A1_with_host_ctor {
  14. using A1_with_host_ctor::A1_with_host_ctor;
  15. };
  16. // expected-note@-4 {{call to __host__ function from __device__}}
  17. // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
  18. // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
  19. // expected-note@-6 2{{constructor from base class 'A1_with_host_ctor' inherited here}}
  20. void hostfoo() {
  21. B1_with_implicit_default_ctor b;
  22. }
  23. __device__ void devicefoo() {
  24. B1_with_implicit_default_ctor b; // expected-error {{no matching constructor}}
  25. }
  26. //------------------------------------------------------------------------------
  27. // Test 2: infer inherited default ctor to be device.
  28. struct A2_with_device_ctor {
  29. __device__ A2_with_device_ctor() {}
  30. };
  31. // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
  32. // expected-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
  33. struct B2_with_implicit_default_ctor : A2_with_device_ctor {
  34. using A2_with_device_ctor::A2_with_device_ctor;
  35. };
  36. // expected-note@-4 {{call to __device__ function from __host__}}
  37. // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
  38. // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
  39. // expected-note@-6 2{{constructor from base class 'A2_with_device_ctor' inherited here}}
  40. void hostfoo2() {
  41. B2_with_implicit_default_ctor b; // expected-error {{no matching constructor}}
  42. }
  43. __device__ void devicefoo2() {
  44. B2_with_implicit_default_ctor b;
  45. }
  46. //------------------------------------------------------------------------------
  47. // Test 3: infer inherited copy ctor
  48. struct A3_with_device_ctors {
  49. __host__ A3_with_device_ctors() {}
  50. __device__ A3_with_device_ctors(const A3_with_device_ctors&) {}
  51. };
  52. struct B3_with_implicit_ctors : A3_with_device_ctors {
  53. using A3_with_device_ctors::A3_with_device_ctors;
  54. };
  55. // expected-note@-3 2{{call to __device__ function from __host__ function}}
  56. // expected-note@-4 {{default constructor}}
  57. void hostfoo3() {
  58. B3_with_implicit_ctors b; // this is OK because the inferred inherited default ctor
  59. // here is __host__
  60. B3_with_implicit_ctors b2 = b; // expected-error {{no matching constructor}}
  61. }
  62. //------------------------------------------------------------------------------
  63. // Test 4: infer inherited default ctor from a field, not a base
  64. struct A4_with_host_ctor {
  65. A4_with_host_ctor() {}
  66. };
  67. struct B4_with_inherited_host_ctor : A4_with_host_ctor{
  68. using A4_with_host_ctor::A4_with_host_ctor;
  69. };
  70. struct C4_with_implicit_default_ctor {
  71. B4_with_inherited_host_ctor field;
  72. };
  73. // expected-note@-4 {{call to __host__ function from __device__}}
  74. // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
  75. // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
  76. void hostfoo4() {
  77. C4_with_implicit_default_ctor b;
  78. }
  79. __device__ void devicefoo4() {
  80. C4_with_implicit_default_ctor b; // expected-error {{no matching constructor}}
  81. }
  82. //------------------------------------------------------------------------------
  83. // Test 5: inherited copy ctor with non-const param
  84. struct A5_copy_ctor_constness {
  85. __host__ A5_copy_ctor_constness() {}
  86. __host__ A5_copy_ctor_constness(A5_copy_ctor_constness&) {}
  87. };
  88. struct B5_copy_ctor_constness : A5_copy_ctor_constness {
  89. using A5_copy_ctor_constness::A5_copy_ctor_constness;
  90. };
  91. // expected-note@-4 {{candidate constructor (the implicit copy constructor) not viable: call to __host__ function from __device__ function}}
  92. // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable}}
  93. void hostfoo5(B5_copy_ctor_constness& b_arg) {
  94. B5_copy_ctor_constness b = b_arg;
  95. }
  96. __device__ void devicefoo5(B5_copy_ctor_constness& b_arg) {
  97. B5_copy_ctor_constness b = b_arg; // expected-error {{no matching constructor}}
  98. }
  99. //------------------------------------------------------------------------------
  100. // Test 6: explicitly defaulted ctor
  101. struct A6_with_device_ctor {
  102. __device__ A6_with_device_ctor() {}
  103. };
  104. struct B6_with_defaulted_ctor : A6_with_device_ctor {
  105. using A6_with_device_ctor::A6_with_device_ctor;
  106. __host__ B6_with_defaulted_ctor() = default;
  107. };
  108. // expected-note@-3 {{explicitly defaulted function was implicitly deleted here}}
  109. // expected-note@-6 {{default constructor of 'B6_with_defaulted_ctor' is implicitly deleted because base class 'A6_with_device_ctor' has no default constructor}}
  110. void hostfoo6() {
  111. B6_with_defaulted_ctor b; // expected-error {{call to implicitly-deleted default constructor}}
  112. }
  113. __device__ void devicefoo6() {
  114. B6_with_defaulted_ctor b;
  115. }
  116. //------------------------------------------------------------------------------
  117. // Test 7: inherited copy assignment operator
  118. struct A7_with_copy_assign {
  119. A7_with_copy_assign() {}
  120. __device__ A7_with_copy_assign& operator=(const A7_with_copy_assign&) {}
  121. };
  122. struct B7_with_copy_assign : A7_with_copy_assign {
  123. using A7_with_copy_assign::A7_with_copy_assign;
  124. };
  125. // expected-note@-4 {{candidate function (the implicit copy assignment operator) not viable: call to __device__ function from __host__ function}}
  126. // expected-note@-5 {{candidate function (the implicit move assignment operator) not viable: call to __device__ function from __host__ function}}
  127. void hostfoo7() {
  128. B7_with_copy_assign b1, b2;
  129. b1 = b2; // expected-error {{no viable overloaded '='}}
  130. }
  131. //------------------------------------------------------------------------------
  132. // Test 8: inherited move assignment operator
  133. // definitions for std::move
  134. namespace std {
  135. inline namespace foo {
  136. template <class T> struct remove_reference { typedef T type; };
  137. template <class T> struct remove_reference<T&> { typedef T type; };
  138. template <class T> struct remove_reference<T&&> { typedef T type; };
  139. template <class T> typename remove_reference<T>::type&& move(T&& t);
  140. }
  141. }
  142. struct A8_with_move_assign {
  143. A8_with_move_assign() {}
  144. __device__ A8_with_move_assign& operator=(A8_with_move_assign&&) {}
  145. __device__ A8_with_move_assign& operator=(const A8_with_move_assign&) {}
  146. };
  147. struct B8_with_move_assign : A8_with_move_assign {
  148. using A8_with_move_assign::A8_with_move_assign;
  149. };
  150. // expected-note@-4 {{candidate function (the implicit copy assignment operator) not viable: call to __device__ function from __host__ function}}
  151. // expected-note@-5 {{candidate function (the implicit move assignment operator) not viable: call to __device__ function from __host__ function}}
  152. void hostfoo8() {
  153. B8_with_move_assign b1, b2;
  154. b1 = std::move(b2); // expected-error {{no viable overloaded '='}}
  155. }