[Clang/AMDGPU] Zero sized arrays not allowed in HIP device code. (#113470)
[llvm-project.git] / clang / test / SemaCXX / cxx2a-template-lambdas.cpp
blob00ba291fbd1981e79c01722bdc09901bd15c0026
1 // RUN: %clang_cc1 -std=c++03 -verify -Dstatic_assert=_Static_assert -Wno-c++11-extensions -Wno-c++14-extensions -Wno-c++17-extensions -Wno-c++20-extensions %s
2 // RUN: %clang_cc1 -std=c++11 -verify=expected,cxx11,cxx11-cxx14 -Wno-c++20-extensions -Wno-c++17-extensions -Wno-c++14-extensions %s
3 // RUN: %clang_cc1 -std=c++14 -verify=expected,cxx11-cxx14,cxx14 -Wno-c++20-extensions -Wno-c++17-extensions %s
4 // RUN: %clang_cc1 -std=c++17 -verify -Wno-c++20-extensions %s
5 // RUN: %clang_cc1 -std=c++20 -verify %s
7 template<typename, typename>
8 inline const bool is_same = false;
10 template<typename T>
11 inline const bool is_same<T, T> = true;
13 template<typename T>
14 struct DummyTemplate { };
16 void func() {
17 auto L0 = []<typename T>(T arg) {
18 static_assert(is_same<T, int>); // expected-error {{static assertion failed}}
20 L0(0);
21 L0(0.0); // expected-note {{in instantiation}}
23 auto L1 = []<int I> {
24 static_assert(I == 5); // expected-error {{static assertion failed}}
26 L1.operator()<5>();
27 L1.operator()<6>(); // expected-note {{in instantiation}}
29 auto L2 = []<template<typename> class T, class U>(T<U> &&arg) {
30 static_assert(is_same<T<U>, DummyTemplate<float> >); // // expected-error {{static assertion failed}}
32 L2(DummyTemplate<float>());
33 L2(DummyTemplate<double>()); // expected-note {{in instantiation}}
36 template<typename T> // expected-note {{declared here}}
37 struct ShadowMe {
38 void member_func() {
39 auto L = []<typename T> { }; // expected-error {{'T' shadows template parameter}}
43 #if __cplusplus >= 201102L
44 template<typename T>
45 constexpr T outer() {
46 // FIXME: The C++11 error seems wrong
47 return []<T x>() { return x; }.template operator()<123>(); // expected-error {{no matching member function}} \
48 expected-note {{candidate template ignored}} \
49 cxx11-note {{non-literal type '<dependent type>' cannot be used in a constant expression}} \
50 cxx14-note {{non-literal type}}
52 static_assert(outer<int>() == 123); // cxx11-cxx14-error {{not an integral constant expression}} cxx11-cxx14-note {{in call}}
53 template int *outer<int *>(); // expected-note {{in instantiation}}
54 #endif
56 #if __cplusplus >= 202002L
57 namespace GH62611 {
58 template <auto A = [](auto x){}>
59 struct C {
60 static constexpr auto B = A;
63 int test() {
64 C<>::B(42);
67 namespace AutoParam
69 template <auto A = [](auto x) { return x;}>
70 auto B = A;
71 static_assert(B<>(42) == 42);
74 namespace TypeParam
76 template <typename T = decltype([](auto x) {return x;})>
77 auto B = T{};
78 static_assert(B<>(42) == 42);
83 namespace GH64689 {
84 void f();
85 void foo() {
86 []<typename T>(int)
87 noexcept(requires(int t) { f(); })
88 -> decltype(requires(int t) { f(); })
89 requires requires(int t) { f(); }
90 {return {};}.operator()<int>(0);
91 [](auto)
92 noexcept(requires(int t) { f(); })
93 -> decltype(requires(int t) { f(); })
94 requires requires(int t) { f(); }
95 {return {};}(1);
99 #endif
101 #if __cplusplus >= 202002L
102 namespace {
103 struct S {};
104 constexpr S gs;
105 void f() {
106 constexpr int x{};
107 const int y{};
108 auto b = []<int=x, int=y>{};
109 using A = decltype([]<int=x>{});
111 int z; // expected-note {{'z' declared here}}
112 auto c = []<int t=z>{
113 // expected-error@-1 {{no matching function for call to object of type}} \
114 // expected-error@-1 {{variable 'z' cannot be implicitly captured in a lambda with no capture-default specified}} \
115 // expected-note@-1 {{lambda expression begins here}} \
116 // expected-note@-1 4{{capture}} \
117 // expected-note@-1 {{candidate template ignored: substitution failure: reference to local variable 'z' declared in enclosing function}}
118 return t;
119 }();
121 auto class_type_global = []<S=gs>{};
123 static constexpr S static_s;
124 auto class_type_static = []<S=static_s>{};
126 constexpr S s; // expected-note {{'s' declared here}}
127 auto class_type = []<S=s>{};
128 // expected-error@-1 {{variable 's' cannot be implicitly captured in a lambda with no capture-default specified}} \
129 // expected-note@-1 {{lambda expression begins here}} \
130 // expected-note@-1 4{{capture}}
133 #endif