xref: /llvm-project/clang/test/SemaTemplate/cxx2a-constraint-caching.cpp (revision 12cb1cb3720de8d164196010123ce1a8901d8122)
1 // RUN:  %clang_cc1 -std=c++2a -verify %s
2 // expected-no-diagnostics
3 
4 template<typename T>
5 concept C = (f(T()), true);
6 
7 template<typename T>
foo()8 constexpr bool foo() { return false; }
9 
10 template<typename T>
f(T ())11   requires (f(T()), true)
12 constexpr bool foo() requires (f(T()), true) { return true; }
13 
14 namespace a {
15   struct A {};
f(A a)16   constexpr void f(A a) {}
17 }
18 
19 static_assert(C<a::A>);
20 static_assert(foo<a::A>());
21 
22 namespace a {
23   // This makes calls to f ambiguous, but the second check will still succeed
24   // because the constraint satisfaction results are cached.
f(A a,int=2)25   constexpr void f(A a, int = 2) {}
26 }
27 static_assert(C<a::A>);
28 static_assert(foo<a::A>());
29