1 // RUN: %clang_cc1 -std=c++20 -verify %s
4 requires(sizeof(T
) > 2) || T::value
// #FOO_REQ
8 void TrailingReturn(T
) // #TRAILING
9 requires(sizeof(T
) > 2) || // #TRAILING_REQ
10 T::value
// #TRAILING_REQ_VAL
14 static constexpr bool value
= B
;
16 static_assert(sizeof(HasValue
<true>) <= 2);
19 struct HasValueLarge
{
20 static constexpr bool value
= B
;
23 static_assert(sizeof(HasValueLarge
<true>) > 2);
26 // Passes the 1st check, short-circuit so the 2nd ::value is not evaluated.
30 // Fails the 1st check, but has a ::value, so the check happens correctly.
31 Foo(HasValue
<true>{});
32 TrailingReturn(HasValue
<true>{});
34 // Passes the 1st check, but would have passed the 2nd one.
35 Foo(HasValueLarge
<true>{});
36 TrailingReturn(HasValueLarge
<true>{});
38 // Fails the 1st check, fails 2nd because there is no ::value.
40 // expected-error@-1{{no matching function for call to 'Foo'}}
41 // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = bool]}}
42 // expected-note@#FOO_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
43 // expected-note@#FOO_REQ{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
46 // expected-error@-1{{no matching function for call to 'TrailingReturn'}}
47 // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = bool]}}
48 // expected-note@#TRAILING_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
49 // expected-note@#TRAILING_REQ_VAL{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
51 // Fails the 1st check, fails 2nd because ::value is false.
52 Foo(HasValue
<false>{});
53 // expected-error@-1 {{no matching function for call to 'Foo'}}
54 // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = HasValue<false>]}}
55 // expected-note@#FOO_REQ{{because 'sizeof(HasValue<false>) > 2' (1 > 2) evaluated to false}}
56 // expected-note@#FOO_REQ{{and 'HasValue<false>::value' evaluated to false}}
57 TrailingReturn(HasValue
<false>{});
58 // expected-error@-1 {{no matching function for call to 'TrailingReturn'}}
59 // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = HasValue<false>]}}
60 // expected-note@#TRAILING_REQ{{because 'sizeof(HasValue<false>) > 2' (1 > 2) evaluated to false}}
61 // expected-note@#TRAILING_REQ_VAL{{and 'HasValue<false>::value' evaluated to false}}