xref: /llvm-project/clang/test/SemaTemplate/constraints.cpp (revision e0cdafe8d4b2f1585f4756447b677fec37954ec4)
16c29073eSRichard Smith // RUN: %clang_cc1 -std=c++20 -verify %s
26c29073eSRichard Smith // RUN: %clang_cc1 -std=c++20 -verify %s -DDEPENDENT_OR
36c29073eSRichard Smith 
46c29073eSRichard Smith #ifdef DEPENDENT_OR
56c29073eSRichard Smith // This causes the || below to be a CXXOperatorCallExpr not a BinaryOperator.
66c29073eSRichard Smith struct A {}; bool operator||(A, A);
76c29073eSRichard Smith #endif
86c29073eSRichard Smith 
96c29073eSRichard Smith namespace PR45589 {
106c29073eSRichard Smith   template<typename T> struct X { static constexpr bool value = T::value; }; // expected-error {{cannot be used prior to '::'}}
116c29073eSRichard Smith   struct False { static constexpr bool value = false; };
126c29073eSRichard Smith   struct True { static constexpr bool value = true; };
136c29073eSRichard Smith 
146c29073eSRichard Smith   template<typename T> concept C = true;
156c29073eSRichard Smith 
166c29073eSRichard Smith   template<bool B, typename T> constexpr int test = 0;
176c29073eSRichard Smith   template<bool B, typename T> requires C<T> constexpr int test<B, T> = 1;
18*e0cdafe8SHaojian Wu   template<bool B, typename T> requires (B && C<T>) || (X<T>::value && C<T>) constexpr int test<B, T> = 2; // expected-note {{instantiation of}} expected-note {{while substituting}}
196c29073eSRichard Smith   static_assert(test<true, False> == 2);
206c29073eSRichard Smith   static_assert(test<true, True> == 2);
216c29073eSRichard Smith   static_assert(test<true, char> == 2); // satisfaction of second term of || not considered
226c29073eSRichard Smith   static_assert(test<false, False> == 1);
236c29073eSRichard Smith   static_assert(test<false, True> == 2); // constraints are partially ordered
24*e0cdafe8SHaojian Wu   static_assert(test<false, char> == 1); // expected-note {{while}} expected-note {{during}}
256c29073eSRichard Smith }
26