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;
11 inline const bool is_same
<T
, T
> = true;
14 struct DummyTemplate
{ };
17 auto L0
= []<typename T
>(T arg
) {
18 static_assert(is_same
<T
, int>); // expected-error {{static assertion failed}}
21 L0(0.0); // expected-note {{in instantiation}}
24 static_assert(I
== 5); // expected-error {{static assertion failed}}
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}}
39 auto L
= []<typename T
> { }; // expected-error {{'T' shadows template parameter}}
43 #if __cplusplus >= 201102L
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}}
56 #if __cplusplus >= 202002L
58 template <auto A
= [](auto x
){}>
60 static constexpr auto B
= A
;
69 template <auto A
= [](auto x
) { return x
;}>
71 static_assert(B
<>(42) == 42);
76 template <typename T
= decltype([](auto x
) {return x
;})>
78 static_assert(B
<>(42) == 42);
87 noexcept(requires(int t
) { f(); })
88 -> decltype(requires(int t
) { f(); })
89 requires
requires(int t
) { f(); }
90 {return {};}.operator()<int>(0);
92 noexcept(requires(int t
) { f(); })
93 -> decltype(requires(int t
) { f(); })
94 requires
requires(int t
) { f(); }
101 #if __cplusplus >= 202002L
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}}
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}}