xref: /aosp_15_r20/external/clang/test/SemaCUDA/implicit-member-target-collision.cu (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li #include "Inputs/cuda.h"
4*67e74705SXin Li 
5*67e74705SXin Li //------------------------------------------------------------------------------
6*67e74705SXin Li // Test 1: collision between two bases
7*67e74705SXin Li 
8*67e74705SXin Li struct A1_with_host_ctor {
A1_with_host_ctorA1_with_host_ctor9*67e74705SXin Li   A1_with_host_ctor() {}
10*67e74705SXin Li };
11*67e74705SXin Li 
12*67e74705SXin Li struct B1_with_device_ctor {
B1_with_device_ctorB1_with_device_ctor13*67e74705SXin Li   __device__ B1_with_device_ctor() {}
14*67e74705SXin Li };
15*67e74705SXin Li 
16*67e74705SXin Li struct C1_with_collision : A1_with_host_ctor, B1_with_device_ctor {
17*67e74705SXin Li };
18*67e74705SXin Li 
19*67e74705SXin Li // expected-note@-3 {{candidate constructor (the implicit default constructor}} not viable
20*67e74705SXin Li // expected-note@-4 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
21*67e74705SXin Li // expected-note@-5 {{candidate constructor (the implicit copy constructor}} not viable
22*67e74705SXin Li 
hostfoo1()23*67e74705SXin Li void hostfoo1() {
24*67e74705SXin Li   C1_with_collision c; // expected-error {{no matching constructor}}
25*67e74705SXin Li }
26*67e74705SXin Li 
27*67e74705SXin Li //------------------------------------------------------------------------------
28*67e74705SXin Li // Test 2: collision between two fields
29*67e74705SXin Li 
30*67e74705SXin Li struct C2_with_collision {
31*67e74705SXin Li   A1_with_host_ctor aa;
32*67e74705SXin Li   B1_with_device_ctor bb;
33*67e74705SXin Li };
34*67e74705SXin Li 
35*67e74705SXin Li // expected-note@-5 {{candidate constructor (the implicit default constructor}} not viable
36*67e74705SXin Li // expected-note@-6 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
37*67e74705SXin Li // expected-note@-7 {{candidate constructor (the implicit copy constructor}} not viable
38*67e74705SXin Li 
hostfoo2()39*67e74705SXin Li void hostfoo2() {
40*67e74705SXin Li   C2_with_collision c; // expected-error {{no matching constructor}}
41*67e74705SXin Li 
42*67e74705SXin Li }
43*67e74705SXin Li 
44*67e74705SXin Li //------------------------------------------------------------------------------
45*67e74705SXin Li // Test 3: collision between a field and a base
46*67e74705SXin Li 
47*67e74705SXin Li struct C3_with_collision : A1_with_host_ctor {
48*67e74705SXin Li   B1_with_device_ctor bb;
49*67e74705SXin Li };
50*67e74705SXin Li 
51*67e74705SXin Li // expected-note@-4 {{candidate constructor (the implicit default constructor}} not viable
52*67e74705SXin Li // expected-note@-5 {{implicit default constructor inferred target collision: call to both __host__ and __device__ members}}
53*67e74705SXin Li // expected-note@-6 {{candidate constructor (the implicit copy constructor}} not viable
54*67e74705SXin Li 
hostfoo3()55*67e74705SXin Li void hostfoo3() {
56*67e74705SXin Li   C3_with_collision c; // expected-error {{no matching constructor}}
57*67e74705SXin Li }
58