Defaulting spaceship operator with custom return type

It appears that the latest Visual Studio compiler can generate operator <=>(...) = default with only 3 standard return types: std::strong_ordering, std::weak_ordering, std::partial_ordering. But is it consistent with the standard?

The most reduced (however purely theoretical) example #1 is as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>struct A {
void operator<=>(const A &) const = default;
};
</code>
<code>struct A { void operator<=>(const A &) const = default; }; </code>
struct A {
    void operator<=>(const A &) const = default;
};

As far as I can see, the only requirement to be satisfied here for a class without subobjects is validity of static_cast<void>(std::strong_ordering::equal), see class.spaceship#3. And indeed both GCC and Clang accept this program, while MSVC complains (demo #1):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>error C7634: 'void': is not a valid comparison type; consider using 'std::strong_ordering' instead
</code>
<code>error C7634: 'void': is not a valid comparison type; consider using 'std::strong_ordering' instead </code>
error C7634: 'void': is not a valid comparison type; consider using 'std::strong_ordering' instead

A longer and more practical example #2:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <compare>
struct A {
int a;
constexpr bool operator==(const A & r) const { return a == r.a; }
constexpr int operator<=>(const A & r) const { return a - r.a; }
};
static_assert(A{1} < A{2});
static_assert(A{3} >= A{2});
struct S : std::strong_ordering {
constexpr S(std::strong_ordering b) : std::strong_ordering(b) {}
constexpr S(int b) : std::strong_ordering(b <=> 0) {}
};
struct B : A {
int b;
S operator<=>(const B &) const = default;
};
static_assert(B{{1},2} < B{{2},1});
static_assert(B{{1},1} <= B{{1},1});
static_assert(B{{3},2} > B{{2},3});
static_assert(B{{2},2} == B{{2},2});
</code>
<code>#include <compare> struct A { int a; constexpr bool operator==(const A & r) const { return a == r.a; } constexpr int operator<=>(const A & r) const { return a - r.a; } }; static_assert(A{1} < A{2}); static_assert(A{3} >= A{2}); struct S : std::strong_ordering { constexpr S(std::strong_ordering b) : std::strong_ordering(b) {} constexpr S(int b) : std::strong_ordering(b <=> 0) {} }; struct B : A { int b; S operator<=>(const B &) const = default; }; static_assert(B{{1},2} < B{{2},1}); static_assert(B{{1},1} <= B{{1},1}); static_assert(B{{3},2} > B{{2},3}); static_assert(B{{2},2} == B{{2},2}); </code>
#include <compare>

struct A {
    int a;
    constexpr bool operator==(const A & r) const { return a == r.a; }
    constexpr int operator<=>(const A & r) const { return a - r.a; }
};

static_assert(A{1} <  A{2});
static_assert(A{3} >= A{2});

struct S : std::strong_ordering {
    constexpr S(std::strong_ordering b) : std::strong_ordering(b) {}
    constexpr S(int b) : std::strong_ordering(b <=> 0) {}
};

struct B : A {
    int b;
    S operator<=>(const B &) const = default;
};

static_assert(B{{1},2} <  B{{2},1});
static_assert(B{{1},1} <= B{{1},1});
static_assert(B{{3},2} >  B{{2},3});
static_assert(B{{2},2} == B{{2},2});

which has custom return type S for spaceship operator able to be constructed from the result of subobject’s comparison operator. This program is again accepted by GCC and Clang, but MSVC first complains and then crashes (demo #2):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><source>(19): error C2280: 'S B::operator <=>(const B &) const': attempting to reference a deleted function
<source>(16): note: see declaration of 'B::operator <=>'
INTERNAL COMPILER ERROR in 'Z:compilersmsvc14.40.33807-14.40.33811.0binHostx64x64cl.exe'
</code>
<code><source>(19): error C2280: 'S B::operator <=>(const B &) const': attempting to reference a deleted function <source>(16): note: see declaration of 'B::operator <=>' INTERNAL COMPILER ERROR in 'Z:compilersmsvc14.40.33807-14.40.33811.0binHostx64x64cl.exe' </code>
<source>(19): error C2280: 'S B::operator <=>(const B &) const': attempting to reference a deleted function
<source>(16): note: see declaration of 'B::operator <=>'
INTERNAL COMPILER ERROR in 'Z:compilersmsvc14.40.33807-14.40.33811.0binHostx64x64cl.exe'

Are both program examples above well formed and Visual Studio’s errors are incorrect?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật