[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / cxx2a-constrained-template-param.cpp
blobd27f0f8db9b885aab1b975734f367a6b5474f89e
1 // RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
3 namespace type
5 template<typename T>
6 concept C1 = true;
8 template<C1 T, C1 U = int>
9 using A = T[10];
11 using a = A<int>;
13 namespace ns {
14 template<typename T, int a = 0>
15 concept C2 = true;
18 template<ns::C2 T1, ::type::ns::C2 T2> requires (sizeof(T1) <= sizeof(T2))
19 struct B { };
21 using b = B<int, int>;
23 template<ns::C2... T1>
24 struct C { };
26 using c1 = C<char, char, char>;
27 using c2 = C<char, char, char, char>;
30 namespace non_type
32 template<int v>
33 concept C1 = true;
35 template<C1 v, C1 u = 0> // expected-error{{expected a type}} // expected-note{{declared here}}
36 // expected-error@-1 2{{concept named in type constraint is not a type concept}}
37 // expected-error@-2 {{expected ',' or '>' in template-parameter-list}}
38 int A = v; // expected-error{{'v' does not refer to a value}}
41 namespace temp
43 template<typename>
44 struct test1 { }; // expected-note{{template is declared here}}
46 template<template<typename> typename T>
47 concept C1 = true;
49 template<C1 TT, C1 UU = test1> // expected-error{{use of class template 'test1' requires template arguments}}
50 // expected-error@-1 2{{concept named in type constraint is not a type concept}}
51 using A = TT<int>; // expected-error{{expected ';' after alias declaration}}
54 namespace PR67235 {
56 template <class T>
57 concept C = true;
59 template <auto D>
60 struct S {};
62 // Don't destroy annotation 'C' at the end of the lambda; else we'll run into a
63 // use-after-free bug while constructing the type constraint 'C' on 'Default'.
64 template <typename Ret, C Default = decltype([] { return Ret(); })>
65 void func() {}
67 template <typename Ret, C Default = S<[] { return Ret(); }>>
68 void func2() {}