implicit-member-target-collision.cu 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // RUN: %clang_cc1 -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. void hostfoo1() {
  17. C1_with_collision c; // expected-error {{no matching constructor}}
  18. }
  19. //------------------------------------------------------------------------------
  20. // Test 2: collision between two fields
  21. struct C2_with_collision {
  22. A1_with_host_ctor aa;
  23. B1_with_device_ctor bb;
  24. };
  25. // expected-note@-5 {{candidate constructor (the implicit default constructor}} not viable
  26. // expected-note@-6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
  27. // expected-note@-7 {{candidate constructor (the implicit copy constructor}} not viable
  28. void hostfoo2() {
  29. C2_with_collision c; // expected-error {{no matching constructor}}
  30. }
  31. //------------------------------------------------------------------------------
  32. // Test 3: collision between a field and a base
  33. struct C3_with_collision : A1_with_host_ctor {
  34. B1_with_device_ctor bb;
  35. };
  36. // expected-note@-4 {{candidate constructor (the implicit default constructor}} not viable
  37. // expected-note@-5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
  38. // expected-note@-6 {{candidate constructor (the implicit copy constructor}} not viable
  39. void hostfoo3() {
  40. C3_with_collision c; // expected-error {{no matching constructor}}
  41. }