Bug 103947 - wishlist: warning if explicitly defaulted (spaceship) operator is deleted
Summary: wishlist: warning if explicitly defaulted (spaceship) operator is deleted
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
Reported: 2022-01-08 00:59 UTC by Frank Heckenbach
Modified: 2022-01-09 05:45 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Frank Heckenbach 2022-01-08 00:59:32 UTC
% cat test.cpp
#include <compare>

struct A { };

struct B: A
  auto operator <=> (const B &) const = default;

int main ()
  B () == B ();
% g++ -std=c++20 -Wall -Wextra test.cpp
test.cpp:7:8: note: 'constexpr bool B::operator==(const B&) const' is implicitly deleted because the default definition would be ill-formed:

This error is correct, of course.

When commenting out the statement in main, though, the program compiles without a warning.

I think a warning would be useful here, since the programmer explicitly declared the defaulted operator, so they wouldn't expect it to be deleted.

In my actual use case, I did get the error where the code tried to use the operator, but that was (a) far removed from that declaration and (b) buried in lots of "candidate" notes (as is common, especially with commonly used operators), so I actually had to grep through the compiler output to find the place where it explained why this (intended) candidate was deleted. A warning right at the declaration would have made it much easier to find.