This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] adds concept std::semiregular
ClosedPublic

Authored by cjdb on Mar 3 2021, 10:06 PM.

Details

Summary

Implements parts of:

  • P0898R3 Standard Library Concepts
  • P1754 Rename concepts to standard_case for C++20, while we still can

Depends on D97443

Diff Detail

Event Timeline

cjdb requested review of this revision.Mar 3 2021, 10:06 PM
cjdb created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2021, 10:06 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
cjdb added a comment.Mar 3 2021, 10:08 PM

While this has mostly been copy/pasted from copyable.compile.pass.cpp, there are some differences, which I've highlighted.

libcxx/test/std/concepts/object/semiregular.compile.pass.cpp
82–83

New test.

104–108

New tests.

145–151

New tests.

EricWF accepted this revision.Mar 4 2021, 2:33 PM
This revision is now accepted and ready to land.Mar 4 2021, 2:33 PM
cjdb updated this revision to Diff 328831.Mar 6 2021, 8:03 PM

rebases to sync with dependencies

Quuxplusone accepted this revision.Mar 7 2021, 5:03 PM

Code looks good, tests look too long — you know the drill.

libcxx/test/std/concepts/object/copyable.h
39 ↗(On Diff #328831)

I'm confused by this change. Was const_copy_assignment already used in the tests for std::copyable? Were those tests intended to check that it was std::copyable despite being not-default-initializable? By making it default-initializable (and thus std::semiregular), are you nerfing the existing std::copyable tests?

libcxx/test/std/concepts/object/semiregular.compile.pass.cpp
13

s/From/T/
(and this probably affects other patches as well)

libcxx/test/std/concepts/object/semiregular.h
18 ↗(On Diff #328831)

We don't need to drag in a dependency on optional here. Also, it's not obvious to me that nullopt_t is inheritable-from; certainly users should not do that. Therefore I strongly recommend replacing this with the following:

struct no_default_ctor { no_default_ctor(int); };
struct derived_from_non_default_initializable : no_default_ctor {};
struct has_non_default_initializable { no_default_ctor x; };

// and/or perhaps also test one with a deleted default ctor? but that'll double the size of the tests again
struct deleted_default_ctor { deleted_default_ctor() = delete; };
cjdb added inline comments.Mar 10 2021, 2:49 PM
libcxx/test/std/concepts/object/copyable.h
39 ↗(On Diff #328831)

The name of the type describes what's going on. This type would have been automatically default-initalisable if I hadn't needed to supply the other constructors to get back copyability (and since the default constructor wasn't necessary at the time, I forgot to add it back in). This type never intended to exclude the default constructor, it just did by accident.

I don't consider it a nerf, because concepts aren't exclusive, and being default_initializable doesn't have any relation to copyable. However since D97443 hasn't landed, I've moved this change over there, along with others (e.g. line 58).

cjdb updated this revision to Diff 330133.Mar 11 2021, 8:13 PM
cjdb marked 2 inline comments as done.

applies @Quuxplusone's feedback (which I thought had already been done)

This revision was automatically updated to reflect the committed changes.