1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 // expected-no-diagnostics
5 struct strong_ordering
{
7 constexpr operator int() const { return n
; }
8 static const strong_ordering less
, equal
, greater
;
10 constexpr strong_ordering
strong_ordering::less
{-1}, strong_ordering::equal
{0}, strong_ordering::greater
{1};
13 // Check that we compare subobjects in the right order.
17 constexpr void add(char c
) { buff
[n
++] = c
; }
18 constexpr bool operator==(const char *p
) const { return __builtin_strcmp(p
, buff
) == 0; }
21 template<char C
> struct B
{
23 constexpr bool operator==(const B
&) const { log
->add(C
); return true; }
24 constexpr std::strong_ordering
operator<=>(const B
&) const { log
->add(C
); return {0}; }
27 template<typename T
> constexpr bool check(bool which
, const char *str
) {
30 (void)(which
? c
== c
: c
<=> c
);
34 struct C
: B
<'a'>, B
<'b'> {
40 constexpr C(Log
*p
) : B
<'a'>{p
}, B
<'b'>{p
}, r
{p
, p
, p
}, c
{p
}, s
{p
, p
}, d
{p
} {}
42 bool operator==(const C
&) const = default;
43 std::strong_ordering
operator<=>(const C
&) const = default;
46 static_assert(check
<C
>(false, "abrrrcssd"));
47 static_assert(check
<C
>(true, "abrrrcssd"));
53 constexpr D(Log
*p
) : x
{p
}, y
{p
, p
} {}
55 bool operator==(const D
&) const = default;
56 std::strong_ordering
operator<=>(const D
&) const = default;
59 static_assert(check
<D
>(false, "xyy"));
60 static_assert(check
<D
>(true, "xyy"));