This is an archive of the discontinued LLVM Phabricator instance.

[libc++][NFC] Reformat and modernize compressed_pair.h
ClosedPublic

Authored by philnik on Feb 9 2022, 6:42 AM.

Diff Detail

Event Timeline

philnik requested review of this revision.Feb 9 2022, 6:42 AM
philnik created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2022, 6:42 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne accepted this revision.Feb 9 2022, 7:33 AM

LGTM, I looked at everything and this is indeed NFC. I don't understand why this is failing in C++03 mode, either.

Ship it but please consider my comments.

libcxx/include/__memory/compressed_pair.h
68

Suggestion: move the explicit to the next line, otherwise it's really easy to miss.

119–120

It's more customary to leave the attributes on the line above, like so:

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
typename _Base1::reference first() _NOEXCEPT { ... }

Otherwise, it's difficult to parse the function declaration itself because it's too obscured by these annotations. I think it's fine to leave the constructors above like _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __compressed_pair_elem() = default; as-is since it allows aligning them and their body is empty anyway, so that's more readable.

This revision is now accepted and ready to land.Feb 9 2022, 7:33 AM
Mordante accepted this revision.Feb 9 2022, 9:22 AM

Nice cleaups! LGTM modulo some style nits and the C++03 breakage..

libcxx/include/__memory/compressed_pair.h
33

Same on line 31.
Just curious did you reformat manually or using clang-format?

38

Needed for C++03.

61
67
philnik updated this revision to Diff 407241.Feb 9 2022, 12:23 PM
philnik marked 6 inline comments as done.
  • Address comments
libcxx/include/__memory/compressed_pair.h
33

I re-formatted manually.

Quuxplusone accepted this revision.Feb 9 2022, 12:23 PM

Looks acceptable to me; I'm not sure it buys us anything, but it looks harmless.

libcxx/include/__memory/compressed_pair.h
68

+1, explicit should come on the same line (and immediately preceding) the ctor's name.
I'd like to see explicit added to the ctors on new lines 63, 64, 65, and 74 as well, or know the reason why that would break things. Implicit conversions are the devil, and we shouldn't need any non-explicit ctors anywhere on the implementation side of things. (As opposed to on the public-API side, like std::pair and std::vector and so on, where the Standard mandates many ctors to be non-explicit.)

94–96

If Clang is happy with this, probable yikes. git grep tells me that the majority position is pre-=:

using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>;

and I'd be worried that post-= meant something different to the compiler.

108

FWIW, I'd prefer to leave this : ... on the next line, for clarity and to match line 115 below.

philnik updated this revision to Diff 407252.Feb 9 2022, 12:43 PM
philnik marked an inline comment as done.
  • Address comments
libcxx/include/__memory/compressed_pair.h
68

I want this to stay NFC, so I won't add explicit here.

This revision was landed with ongoing or failed builds.Feb 10 2022, 4:41 AM
This revision was automatically updated to reflect the committed changes.