[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / invalid-requirement-requires-expr.cpp
blob097ada3caa135370fae1a92d567bfe8713a20783
1 // RUN: %clang -fsyntax-only -std=c++2a -Xclang -verify -ftemplate-depth=5 -ftemplate-backtrace-limit=4 %s
3 // RequiresExpr contains invalid requirement. (Eg. Highly recurisive template).
4 template<int x>
5 struct A { static constexpr bool far(); };
6 class B {
7 bool data_member;
8 friend struct A<1>;
9 };
11 template<>
12 constexpr bool A<0>::far() { return true; }
14 template<int x>
15 constexpr bool A<x>::far() {
16 return requires(B b) {
17 b.data_member;
18 requires A<x-1>::far(); // #Invalid
19 // expected-error@#Invalid {{recursive template instantiation exceeded maximum depth}}
20 // expected-note@#Invalid {{in instantiation}}
21 // expected-note@#Invalid 2 {{while}}
22 // expected-note@#Invalid {{contexts in backtrace}}
23 // expected-note@#Invalid {{increase recursive template instantiation depth}}
26 static_assert(A<1>::far());
27 static_assert(!A<6>::far()); // expected-note {{in instantiation of member function}}