Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / cxx2a-template-lambdas.cpp
blob7ac48136989146f71fa9be8f0fcdbb3f6f8a5654
1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 template<typename, typename>
4 constexpr bool is_same = false;
6 template<typename T>
7 constexpr bool is_same<T, T> = true;
9 template<typename T>
10 struct DummyTemplate { };
12 void func() {
13 auto L0 = []<typename T>(T arg) {
14 static_assert(is_same<T, int>); // expected-error {{static assertion failed}}
16 L0(0);
17 L0(0.0); // expected-note {{in instantiation}}
19 auto L1 = []<int I> {
20 static_assert(I == 5); // expected-error {{static assertion failed}}
22 L1.operator()<5>();
23 L1.operator()<6>(); // expected-note {{in instantiation}}
25 auto L2 = []<template<typename> class T, class U>(T<U> &&arg) {
26 static_assert(is_same<T<U>, DummyTemplate<float>>); // // expected-error {{static assertion failed}}
28 L2(DummyTemplate<float>());
29 L2(DummyTemplate<double>()); // expected-note {{in instantiation}}
32 template<typename T> // expected-note {{declared here}}
33 struct ShadowMe {
34 void member_func() {
35 auto L = []<typename T> { }; // expected-error {{'T' shadows template parameter}}
39 template<typename T>
40 constexpr T outer() {
41 return []<T x>() { return x; }.template operator()<123>(); // expected-error {{no matching member function}} \
42 expected-note {{candidate template ignored}}
44 static_assert(outer<int>() == 123);
45 template int *outer<int *>(); // expected-note {{in instantiation}}
48 namespace GH62611 {
49 template <auto A = [](auto x){}>
50 struct C {
51 static constexpr auto B = A;
54 int test() {
55 C<>::B(42);
58 namespace AutoParam
60 template <auto A = [](auto x) { return x;}>
61 auto B = A;
62 static_assert(B<>(42) == 42);
65 namespace TypeParam
67 template <typename T = decltype([](auto x) {return x;})>
68 auto B = T{};
69 static_assert(B<>(42) == 42);
74 namespace GH64689 {
75 void f();
76 void foo() {
77 []<typename T>(int)
78 noexcept(requires(int t) { f(); })
79 -> decltype(requires(int t) { f(); })
80 requires requires(int t) { f(); }
81 {return {};}.operator()<int>(0);
82 [](auto)
83 noexcept(requires(int t) { f(); })
84 -> decltype(requires(int t) { f(); })
85 requires requires(int t) { f(); }
86 {return {};}(1);