xref: /llvm-project/clang/test/SemaCXX/invalid-requirement-requires-expr.cpp (revision 15ad244670a9ef0bf93b7c8a598586d4a841b197)
1 // RUN: %clang -fsyntax-only -std=c++2a -Xclang -verify -ftemplate-depth=5 -ftemplate-backtrace-limit=4 %s
2 
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 };
10 
11 template<>
far()12 constexpr bool A<0>::far() { return true; }
13 
14 template<int x>
far()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}}
24     };
25 }
26 static_assert(A<1>::far());
27 static_assert(!A<6>::far()); // expected-note {{in instantiation of member function}}
28