llvm-project
80 строк · 2.2 Кб
1// RUN: %clang_cc1 -std=c++14 %s -triple nvptx64-nvidia-cuda \
2// RUN: -fcuda-is-device -verify -fsyntax-only
3// RUN: %clang_cc1 -std=c++17 %s -triple nvptx64-nvidia-cuda \
4// RUN: -fcuda-is-device -verify -fsyntax-only
5// RUN: %clang_cc1 -std=c++14 %s \
6// RUN: -triple x86_64-unknown-linux-gnu -verify -fsyntax-only
7// RUN: %clang_cc1 -std=c++17 %s \
8// RUN: -triple x86_64-unknown-linux-gnu -verify -fsyntax-only
9#include "Inputs/cuda.h"
10
11template<typename T>
12__host__ __device__ void foo(const T **a) {
13// expected-note@-1 {{declared here}}
14static const T b = sizeof(a);
15static constexpr T c = sizeof(a);
16const T d = sizeof(a);
17constexpr T e = sizeof(a);
18constexpr T f = **a;
19// expected-error@-1 {{constexpr variable 'f' must be initialized by a constant expression}}
20// expected-note@-2 {{}}
21a[0] = &b;
22a[1] = &c;
23a[2] = &d;
24a[3] = &e;
25}
26
27__device__ void device_fun(const int **a) {
28// expected-note@-1 {{declared here}}
29constexpr int b = sizeof(a);
30static constexpr int c = sizeof(a);
31constexpr int d = **a;
32// expected-error@-1 {{constexpr variable 'd' must be initialized by a constant expression}}
33// expected-note@-2 {{}}
34a[0] = &b;
35a[1] = &c;
36foo(a);
37// expected-note@-1 {{in instantiation of function template specialization 'foo<int>' requested here}}
38}
39
40void host_fun(const int **a) {
41// expected-note@-1 {{declared here}}
42constexpr int b = sizeof(a);
43static constexpr int c = sizeof(a);
44constexpr int d = **a;
45// expected-error@-1 {{constexpr variable 'd' must be initialized by a constant expression}}
46// expected-note@-2 {{}}
47a[0] = &b;
48a[1] = &c;
49foo(a);
50}
51
52__host__ __device__ void host_device_fun(const int **a) {
53// expected-note@-1 {{declared here}}
54constexpr int b = sizeof(a);
55static constexpr int c = sizeof(a);
56constexpr int d = **a;
57// expected-error@-1 {{constexpr variable 'd' must be initialized by a constant expression}}
58// expected-note@-2 {{}}
59a[0] = &b;
60a[1] = &c;
61foo(a);
62}
63
64template <class T>
65struct A {
66explicit A() = default;
67};
68template <class T>
69constexpr A<T> a{};
70
71struct B {
72static constexpr bool value = true;
73};
74
75template<typename T>
76struct C {
77static constexpr bool value = T::value;
78};
79
80__constant__ const bool &x = C<B>::value;
81