xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCUDA/implicit-member-target-collision.cu (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -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: collision between two bases
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 struct B1_with_device_ctor {
B1_with_device_ctorB1_with_device_ctor13*0a6a1f1dSLionel Sambuc   __device__ B1_with_device_ctor() {}
14*0a6a1f1dSLionel Sambuc };
15*0a6a1f1dSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc struct C1_with_collision : A1_with_host_ctor, B1_with_device_ctor {
17*0a6a1f1dSLionel Sambuc };
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc // expected-note@-3 {{candidate constructor (the implicit default constructor}} not viable
20*0a6a1f1dSLionel Sambuc // expected-note@-4 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
21*0a6a1f1dSLionel Sambuc // expected-note@-5 {{candidate constructor (the implicit copy constructor}} not viable
22*0a6a1f1dSLionel Sambuc 
hostfoo1()23*0a6a1f1dSLionel Sambuc void hostfoo1() {
24*0a6a1f1dSLionel Sambuc   C1_with_collision c; // expected-error {{no matching constructor}}
25*0a6a1f1dSLionel Sambuc }
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------
28*0a6a1f1dSLionel Sambuc // Test 2: collision between two fields
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc struct C2_with_collision {
31*0a6a1f1dSLionel Sambuc   A1_with_host_ctor aa;
32*0a6a1f1dSLionel Sambuc   B1_with_device_ctor bb;
33*0a6a1f1dSLionel Sambuc };
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc // expected-note@-5 {{candidate constructor (the implicit default constructor}} not viable
36*0a6a1f1dSLionel Sambuc // expected-note@-6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
37*0a6a1f1dSLionel Sambuc // expected-note@-7 {{candidate constructor (the implicit copy constructor}} not viable
38*0a6a1f1dSLionel Sambuc 
hostfoo2()39*0a6a1f1dSLionel Sambuc void hostfoo2() {
40*0a6a1f1dSLionel Sambuc   C2_with_collision c; // expected-error {{no matching constructor}}
41*0a6a1f1dSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc }
43*0a6a1f1dSLionel Sambuc 
44*0a6a1f1dSLionel Sambuc //------------------------------------------------------------------------------
45*0a6a1f1dSLionel Sambuc // Test 3: collision between a field and a base
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc struct C3_with_collision : A1_with_host_ctor {
48*0a6a1f1dSLionel Sambuc   B1_with_device_ctor bb;
49*0a6a1f1dSLionel Sambuc };
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc // expected-note@-4 {{candidate constructor (the implicit default constructor}} not viable
52*0a6a1f1dSLionel Sambuc // expected-note@-5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
53*0a6a1f1dSLionel Sambuc // expected-note@-6 {{candidate constructor (the implicit copy constructor}} not viable
54*0a6a1f1dSLionel Sambuc 
hostfoo3()55*0a6a1f1dSLionel Sambuc void hostfoo3() {
56*0a6a1f1dSLionel Sambuc   C3_with_collision c; // expected-error {{no matching constructor}}
57*0a6a1f1dSLionel Sambuc }
58