[PATCH] D45680: [C++2a] Add operator<=> Rewriting - Early Attempt

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 16 01:15:48 PDT 2018


EricWF created this revision.
EricWF added a reviewer: rsmith.
Herald added a subscriber: mgrang.

This is a work-in-progress attempt to add `operator<=>` rewriting. It's nowhere close to complete, but I would like some initial feedback on the direction.

As currently implemented, rewritten and synthesized candidates are only partially checked for viability when they're added to the overload candidates (the conversion sequence from the argument type -> parameter type is checked, but nothing else). This can lead non-viable candidates being selected or causing ambiguity when final overload resolution is attempted.

The solution implemented in this patch is to fully build "potentially viable" candidates if they are selected or cause ambiguity. If building the candidate fails, it is marked as non-viable, and a new best viable function is computed.

The problem with this approach is that it's expensive and potentially wasteful. For example, if overload resolution results in ambiguity with `N` rewritten candidates with the same partial ordering, then all `N` candidates are fully built, and those results potentially thrown away.

For builtin candidates this can be avoided by separating out the bits of `CheckBinaryOperands` which compute it's result type from the bits which actually build the expression and convert the arguments. Once we know the return type of the builtin, we can deduce if the comparison category type can be used in the expression `0 @ <comp-category>` without much effect.

However, for non-builtin overloads of `operator<=>` (which don't return a comparison category type), it seems non-trivial to check that `0 @ <result>` is valid without actually attempting to build the overloaded binary operator.

@rsmith Could you provide initial feedback on this direction? Or any ideas you have about how to best implement it?


Repository:
  rC Clang

https://reviews.llvm.org/D45680

Files:
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/Sema/SemaOverload.cpp
  test/SemaCXX/compare-cxx2a.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45680.142602.patch
Type: text/x-patch
Size: 42631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180416/1b55c851/attachment-0001.bin>


More information about the cfe-commits mailing list