Page MenuHomePhabricator

[clang] Exclude function pointers on DefaultedComparisonAnalyzer

Authored by mizvekov on Mon, Jun 7, 4:51 PM.



This implements a more comprehensive fix than was done at D95409.
Instead of excluding just function pointer subobjects, we also
exclude any user-defined function pointer conversion operators.

Signed-off-by: Matheus Izvekov <>

Diff Detail

Event Timeline

mizvekov created this revision.Mon, Jun 7, 4:51 PM
mizvekov requested review of this revision.Mon, Jun 7, 4:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMon, Jun 7, 4:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I think we need to take this to the C++ committee. For example, consider a case like:

struct A {
  using T1 = void(*)();
  using T2 = int;
  operator T1();
  operator T2();
struct B {
  A a;
  friend auto operator<=>(B, B) = default;

Under the standard rules, the operator<=> is deleted due to ambiguity, but with this change we'd unambiguously pick the conversion to T2. The old behavior here better matches the current standard wording -- in particular, the special case is in []/3.2 and only applies when neither operand is of overloadable type -- but perhaps the right approach here would be to fix the language rules so that operator<=> is only provided for object pointer types, not for all pointer types, in general.

I see. I can change this patch so it just implicitly deletes the operator in case we decide to pick function pointers, without the hard error introduced by the previous patch.
And if the comitee decides to stop providing relational operators for function pointers, we can revisit this.

mizvekov updated this revision to Diff 352667.Thu, Jun 17, 3:38 AM

Instead of excluding function pointers from the overload set, just implicitly delete
with new diagnostic in case we end up selecting it.

rsmith accepted this revision.Thu, Jun 17, 1:03 PM

Thanks, let's go with this for now.

Discussion in WG21 seems to be heading towards removing the builtin candidates for operator<=>, operator<, operator<=, operator>, and operator>= for function pointers, but we'll probably not have a firm decision on that for quite a while.

This revision is now accepted and ready to land.Thu, Jun 17, 1:03 PM
This revision was landed with ongoing or failed builds.Fri, Jun 18, 4:07 AM
This revision was automatically updated to reflect the committed changes.
lhames added a subscriber: lhames.Fri, Jun 18, 6:54 PM

Disregard 80f30a6b855b: I messed up a copy-paste of a commit message. That was for