This is an archive of the discontinued LLVM Phabricator instance.

[clang] Stop providing builtin overload candidate for relational function pointer comparisons
ClosedPublic

Authored by mizvekov on Jun 24 2021, 6:53 PM.

Details

Summary

Word on the grapevine was that the committee had some discussion that
ended with unanimous agreement on eliminating relational function pointer comparisons.

We wanted to be bold and just ban all of them cold turkey.
But then we chickened out at the last second and are going for
eliminating just the spaceship overload candidate instead, for now.

See D104680 for reference.

This should be fine and "safe", because the only possible semantic change this
would cause is that overload resolution could possibly be ambiguous if
there was another viable candidate equally as good.

But to save face a little we are going to:

  • Issue an "error" for three-way comparisons on function pointers. But all this is doing really is changing one vague error message, from an "invalid operands to binary expression" into an "ordered comparison of function pointers", which sounds more like we mean business.
  • Otherwise "warn" that comparing function pointers like that is totally not cool (unless we are told to keep quiet about this).

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov requested review of this revision.Jun 24 2021, 6:53 PM
mizvekov created this revision.
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 24 2021, 6:53 PM
Herald added subscribers: Restricted Project, cfe-commits. · View Herald Transcript
mizvekov edited the summary of this revision. (Show Details)Jun 24 2021, 6:58 PM

Thanks, the summary gave me a chuckle :)

clang/lib/Sema/SemaExpr.cpp
11809–11812

In C++, non-IsError cases, this should be a warn_... diagnostic that is a Warning<...>, rather than an ext_... diagnostic that is an ExtWarn<...>, otherwise we'll reject this in -pedantic-errors mode. (That's what's happening in test/CXX/drs/dr15xx.cpp.)

mizvekov updated this revision to Diff 354595.Jun 25 2021, 1:38 PM
  • Make it a regular warning.
mizvekov edited the summary of this revision. (Show Details)Jun 25 2021, 1:38 PM
mizvekov marked an inline comment as done.Jun 25 2021, 1:40 PM
rsmith accepted this revision.Jun 25 2021, 2:04 PM

A couple of comments on test coverage but otherwise this looks great, thanks! It'll be instructive to see if people ask for the warning to not be on by default...

clang/test/CXX/expr/expr.const/p2-0x.cpp
517

Can you undo this change now? We should retain some test coverage ensuring that we fail constant evaluation in this case.

clang/test/FixIt/fixit.cpp
298–303

We should retain some test coverage that we produce a proper fixit when splitting >>= into > >=. If you want to move this test away from function pointer comparison, we can test the same thing with variable templates these days.

This revision is now accepted and ready to land.Jun 25 2021, 2:04 PM
mizvekov updated this revision to Diff 354607.Jun 25 2021, 2:38 PM
  • Restore tests.
  • Reimplement fixit in terms of variable template (needs -Wno-c++14-extensions).
mizvekov marked 2 inline comments as done.Jun 25 2021, 2:40 PM
This revision was landed with ongoing or failed builds.Jun 25 2021, 3:08 PM
This revision was automatically updated to reflect the committed changes.