This is an archive of the discontinued LLVM Phabricator instance.

[Clang][C++20] Error out if parameter types of a defaulted comparison operator aren't as expected.
ClosedPublic

Authored by massberg on May 23 2023, 4:15 AM.

Details

Summary

A defaulted comparison operator C should be

  • a member of C having one parameter of type const C& or
  • a friend of C having either two parameters of type const C& or two parameters of type C

see e.g. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2002r1.html

C++20 allows defaulted comparison operators for dependent types. This patch adds the logic to check whether the parameters have the right form
for dependent types.

This fixes #62880

Diff Detail

Event Timeline

massberg created this revision.May 23 2023, 4:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 4:15 AM
massberg requested review of this revision.May 23 2023, 4:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 4:15 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I just realized that we should probably also enable the other check (err_defaulted_comparison_param) for dependent types.

massberg updated this revision to Diff 524704.May 23 2023, 7:25 AM

Also error out if the comparion operator has a single parameter that isn't a const reference. See also https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2002r1.html on how it shpuld behave in C++20.

massberg retitled this revision from [Clang][C++20] Error out if parameter types of a defaulted comparion operator are not all the same. to [Clang][C++20] Error out if parameter types of a defaulted comparison operator aren't as expected..May 23 2023, 7:30 AM
massberg edited the summary of this revision. (Show Details)
shafik accepted this revision.May 23 2023, 8:24 AM
shafik added a reviewer: Restricted Project.
This revision is now accepted and ready to land.May 23 2023, 8:24 AM
shafik accepted this revision.May 23 2023, 8:25 AM

LGTM assuming precommit CI comes back green