implicit-member-target-collision-cxx11.cu 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
  2. #include "Inputs/cuda.h"
  3. //------------------------------------------------------------------------------
  4. // Test 1: collision between two bases
  5. struct A1_with_host_ctor {
  6. A1_with_host_ctor() {}
  7. };
  8. struct B1_with_device_ctor {
  9. __device__ B1_with_device_ctor() {}
  10. };
  11. struct C1_with_collision : A1_with_host_ctor, B1_with_device_ctor {
  12. };
  13. // expected-note@-3 {{candidate constructor (the implicit default constructor) not viable}}
  14. // expected-note@-4 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
  15. // expected-note@-5 {{candidate constructor (the implicit copy constructor) not viable}}
  16. // expected-note@-6 {{candidate constructor (the implicit move constructor) not viable}}
  17. void hostfoo1() {
  18. C1_with_collision c; // expected-error {{no matching constructor}}
  19. }
  20. //------------------------------------------------------------------------------
  21. // Test 2: collision between two fields
  22. struct C2_with_collision {
  23. A1_with_host_ctor aa;
  24. B1_with_device_ctor bb;
  25. };
  26. // expected-note@-5 {{candidate constructor (the implicit default constructor}} not viable
  27. // expected-note@-6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
  28. // expected-note@-7 {{candidate constructor (the implicit copy constructor}} not viable
  29. // expected-note@-8 {{candidate constructor (the implicit move constructor}} not viable
  30. void hostfoo2() {
  31. C2_with_collision c; // expected-error {{no matching constructor}}
  32. }
  33. //------------------------------------------------------------------------------
  34. // Test 3: collision between a field and a base
  35. struct C3_with_collision : A1_with_host_ctor {
  36. B1_with_device_ctor bb;
  37. };
  38. // expected-note@-4 {{candidate constructor (the implicit default constructor}} not viable
  39. // expected-note@-5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
  40. // expected-note@-6 {{candidate constructor (the implicit copy constructor}} not viable
  41. // expected-note@-7 {{candidate constructor (the implicit move constructor}} not viable
  42. void hostfoo3() {
  43. C3_with_collision c; // expected-error {{no matching constructor}}
  44. }
  45. //------------------------------------------------------------------------------
  46. // Test 4: collision on resolving a copy ctor
  47. struct A4_with_host_copy_ctor {
  48. A4_with_host_copy_ctor() {}
  49. A4_with_host_copy_ctor(const A4_with_host_copy_ctor&) {}
  50. };
  51. struct B4_with_device_copy_ctor {
  52. B4_with_device_copy_ctor() {}
  53. __device__ B4_with_device_copy_ctor(const B4_with_device_copy_ctor&) {}
  54. };
  55. struct C4_with_collision : A4_with_host_copy_ctor, B4_with_device_copy_ctor {
  56. };
  57. // expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable: call to invalid function from __host__ function}}
  58. // expected-note@-4 {{implicit copy constructor inferred target collision: call to both __host__ and __device__ members}}
  59. // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
  60. void hostfoo4() {
  61. C4_with_collision c;
  62. C4_with_collision c2 = c; // expected-error {{no matching constructor for initialization of 'C4_with_collision'}}
  63. }
  64. //------------------------------------------------------------------------------
  65. // Test 5: collision on resolving a move ctor
  66. struct A5_with_host_move_ctor {
  67. A5_with_host_move_ctor() {}
  68. A5_with_host_move_ctor(A5_with_host_move_ctor&&) {}
  69. // expected-note@-1 {{copy constructor is implicitly deleted because 'A5_with_host_move_ctor' has a user-declared move constructor}}
  70. };
  71. struct B5_with_device_move_ctor {
  72. B5_with_device_move_ctor() {}
  73. __device__ B5_with_device_move_ctor(B5_with_device_move_ctor&&) {}
  74. };
  75. struct C5_with_collision : A5_with_host_move_ctor, B5_with_device_move_ctor {
  76. };
  77. // expected-note@-2 {{deleted}}
  78. void hostfoo5() {
  79. C5_with_collision c;
  80. // What happens here:
  81. // This tries to find the move ctor. Since the move ctor is deleted due to
  82. // collision, it then looks for a copy ctor. But copy ctors are implicitly
  83. // deleted when move ctors are declared explicitly.
  84. C5_with_collision c2(static_cast<C5_with_collision&&>(c)); // expected-error {{call to implicitly-deleted}}
  85. }