Clang Project

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