This is an archive of the discontinued LLVM Phabricator instance.

[clang] implicitly delete space ship operator with function pointers
ClosedPublic

Authored by mizvekov on Jan 25 2021, 4:32 PM.

Details

Summary

See bug #48856

Definitions of classes with member function pointers and default
spaceship operator were getting accepted with no diagnostic on
release build, and triggering assert on builds with runtime checks
enabled. Diagnostics were only produced when actually comparing
instances of such classes.

This patch makes it so Spaceship and Less operators are not considered
as builtin operator candidates for function pointers, producing
equivalent diagnostics for the cases where pointers to member function
and pointers to data members are used instead.

Diff Detail

Event Timeline

mizvekov created this revision.Jan 25 2021, 4:32 PM
mizvekov requested review of this revision.Jan 25 2021, 4:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2021, 4:32 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
mizvekov updated this revision to Diff 319400.Jan 26 2021, 1:22 PM

added tests

adds test that will catch original bug
also adds some tests on default equality/relational operators

this last one would have caught the issue of not accepting equality
operator for function pointers, had I not remembered about it :)

Ping.

By the way I realize I may not have put the new tests in the appropriate place. Any guidance there welcome.

Thanks, this looks fine. I wish we had a better way to determine whether a builtin comparison is usable without actually building a use of it. :-(

By the way I realize I may not have put the new tests in the appropriate place. Any guidance there welcome.

I've suggested better locations.

clang/lib/Sema/SemaDeclCXX.cpp
7688–7690

Please can you extend the FIXME comment below to call out that relational comparisons on a function pointer is the one known case where there is a builtin candidate that can't actually be used?

clang/test/CXX/class/class.compare/class.compare.default/p6.cpp
1 ↗(On Diff #319400)

Hm, I don't think this is the right place for this test. The A test is a test for [class.compare.default]p2 (which disallows reference members). The B, C, and D tests are for [class.eq]p2 (which requires xi == xi to be a usable expression). Can you move the tests to those places?

clang/test/CXX/class/class.compare/class.spaceship/p4.cpp
19 ↗(On Diff #319400)

Similar to above, this is [class.compare.default]p2.

34 ↗(On Diff #319400)

... and these are [class.spaceship]p2 ("The operator function is defined as deleted if that expression is not usable")

mizvekov updated this revision to Diff 326514.Feb 25 2021, 2:40 PM

Updated comment and moved tests to correct places.

rsmith accepted this revision.Feb 26 2021, 3:18 PM
This revision is now accepted and ready to land.Feb 26 2021, 3:18 PM