Debian Codegraph @

clang/test/SemaCXX/cxx2a-template-lambdas.cpp

raw
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
6
7 template<typename, typename>
8 inline const bool is_same = false;
9
10 template<typename T>
11 inline const bool is_same<T, T> = true;
12
13 template<typename T>
14 struct DummyTemplate { };
15
16 void func() {
17 auto L0 = []<typename T>(T arg) {
18 static_assert(is_same<T, int>); // expected-error {{static assertion failed}}
19 };
20 L0(0);
21 L0(0.0); // expected-note {{in instantiation}}
22
23 auto L1 = []<int I> {
24 static_assert(I == 5); // expected-error {{static assertion failed}}
25 };
26 L1.operator()<5>();
27 L1.operator()<6>(); // expected-note {{in instantiation}}
28
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}}
31 };
32 L2(DummyTemplate<float>());
33 L2(DummyTemplate<double>()); // expected-note {{in instantiation}}
34 }
35
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}}
40 }
41 };
42
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}}
51 }
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
55
56 #if __cplusplus >= 202002L
57 namespace GH62611 {
58 template <auto A = [](auto x){}>
59 struct C {
60 static constexpr auto B = A;
61 };
62
63 int test() {
64 C<>::B(42);
65 }
66
67 namespace AutoParam
68 {
69 template <auto A = [](auto x) { return x;}>
70 auto B = A;
71 static_assert(B<>(42) == 42);
72 }
73
74 namespace TypeParam
75 {
76 template <typename T = decltype([](auto x) {return x;})>
77 auto B = T{};
78 static_assert(B<>(42) == 42);
79 }
80
81 }
82
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);
96 }
97
98 }
99 #endif