Three-way comparison (<=>) with anonymous structs
07:18 16 Feb 2026

Maybe I'm missing something, but there seems to be no way to declare a defaulted three-way comparison operator in anonymous structs. It seems that you are forced to name the struct, to have a concrete type to use in the declaration.

struct Foo {
    auto operator<=>(const Foo &) const = default;

    std::string bar;

    struct {
        // auto operator<=>(const  &) const = default;
    
        int baz;
    } qux;
};

Is this expected behavior and/or an oversight?

c++ c++20 spaceship-operator