Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -7276,6 +7276,9 @@ return; } + if (DefKind.isComparison()) + UnusedPrivateFields.clear(); + if (DefKind.isSpecialMember() ? CheckExplicitlyDefaultedSpecialMember(cast(FD), DefKind.asSpecialMember()) Index: clang/test/SemaCXX/warn-unused-private-field.cpp =================================================================== --- clang/test/SemaCXX/warn-unused-private-field.cpp +++ clang/test/SemaCXX/warn-unused-private-field.cpp @@ -1,5 +1,24 @@ // RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s // RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++17 %s +// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s + +#if __cplusplus >= 202002L + +class EqDefaultCompare { + int unused_; + +public: + bool operator==(const EqDefaultCompare &) const = default; +}; + +class SpaceShipDefaultCompare { + int unused_; + +public: + int operator<=>(const SpaceShipDefaultCompare &) const = default; +}; + +#endif class NotFullyDefined { public: