This is an archive of the discontinued LLVM Phabricator instance.

[clang] Exclude function pointers on DefaultedComparisonAnalyzer
ClosedPublic

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

Details

Summary

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 <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov created this revision.Jun 7 2021, 4:51 PM
mizvekov requested review of this revision.Jun 7 2021, 4:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2021, 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 [class.compare.default]/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.Jun 17 2021, 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.Jun 17 2021, 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.Jun 17 2021, 1:03 PM
This revision was landed with ongoing or failed builds.Jun 18 2021, 4:07 AM
This revision was automatically updated to reflect the committed changes.
lhames added a subscriber: lhames.Jun 18 2021, 6:54 PM

Disregard 80f30a6b855b: I messed up a copy-paste of a commit message. That was for https://reviews.llvm.org/D104480.