This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Make sure we don't eagerly diagnose non-const comparators for containers of incomplete types
ClosedPublic

Authored by ldionne on Apr 10 2019, 3:02 PM.

Details

Summary

In r348529, I improved the library-defined diagnostic for using containers
with a non-const comparator/hasher. However, the check is now performed
too early, which leads to the diagnostic being emitted in cases where it
shouldn't. See PR41360 for details.

This patch moves the diagnostic to the destructor of the containers, which
means that the diagnostic will only be emitted when the container is instantiated
at a point where the comparator and the key/value are required to be complete.
We still retain better diagnostics than before r348529, because the diagnostics
are performed in the containers themselves instead of tree and hash_table.

Diff Detail

Repository
rL LLVM

Event Timeline

ldionne created this revision.Apr 10 2019, 3:02 PM
ldionne marked an inline comment as done.Apr 10 2019, 3:07 PM
ldionne added inline comments.
libcxx/test/libcxx/containers/unord/non_const_comparator.pass.cpp
41–42 ↗(On Diff #194593)

Note: those two tests fail, I need to figure out why (tomorrow). I still wanted to get the patch out there to get feedback if there's any.

The fix LGTM. I'll try to figure out what's going on with the tests

zoecarver added inline comments.Apr 10 2019, 9:38 PM
libcxx/test/libcxx/containers/unord/non_const_comparator.pass.cpp
41–42 ↗(On Diff #194593)

Looked into it a bit but can't seem to figure it out either 😕. My guess is that __check_hash_requirements is being called before Derived is completed (somehow).

EricWF added inline comments.Apr 10 2019, 10:21 PM
libcxx/test/libcxx/containers/unord/non_const_comparator.pass.cpp
41–42 ↗(On Diff #194593)

The map tests are incorrect. They pass Derived* as the key type and std::less<Base*> as the value type. That might be why they're passing but the set tests are not.

ldionne updated this revision to Diff 194702.Apr 11 2019, 8:51 AM
ldionne marked 2 inline comments as done.

Fix broken tests.

libcxx/test/libcxx/containers/unord/non_const_comparator.pass.cpp
41–42 ↗(On Diff #194593)

Wow, thanks. IDK what I was thinking -- this needs to be Container<Key, Value, std::hash<Key>, std::equal_to<Key>>. This was all wrong. The tests pass when I fix that. Like I said, this was the end of a long day!

EricWF accepted this revision.Apr 11 2019, 9:11 AM

It took me a couple of passes to spot it.

LGTM. thanks for the fix

This revision is now accepted and ready to land.Apr 11 2019, 9:11 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2019, 9:13 AM