This is an archive of the discontinued LLVM Phabricator instance.

[libc++][NFC] Add namespace comments in ranges
ClosedPublic

Authored by philnik on Jan 31 2022, 4:42 PM.

Details

Summary

With this patch there should be no more namespaces without closing comment

Diff Detail

Event Timeline

philnik requested review of this revision.Jan 31 2022, 4:42 PM
philnik created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2022, 4:43 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik added inline comments.Jan 31 2022, 4:56 PM
libcxx/include/__ranges/reverse_view.h
117

Here, in line 123 and line 129 clang-tidy claims these definitions can lead to ODR-violations. Is inline implied by it being a template or something else and therefore this is a clang-tidy bug or is this actually potentially an ODR-violation and this is a libc++ bug?

ldionne accepted this revision.Jan 31 2022, 5:56 PM

The patch itself LGTM, but there's indeed an interesting side question about the linkage of variable templates.

libcxx/include/__ranges/reverse_view.h
117

I'll use cppreference instead of the standard here because everything I found in the Standard was much harder to understand than cppreference.

My understanding is that the __is_reverse_view base template has the usual linkage for templates, which is extern inline (more precisely linkonce_odr in LLVM lingo). See external linkage at https://en.cppreference.com/w/cpp/language/storage_duration.

However, the __is_reverse_view<reverse_view<_Tp>> specialization is a variable, not a variable template, so this part of https://en.cppreference.com/w/cpp/language/storage_duration / internal linkage applies to it instead:

non-volatile non-template non-inline non-exported const-qualified variables (including constexpr) that aren't declared extern and aren't previously declared to have external linkage;

Naively, this would mean that __is_reverse_view<reverse_view<_Tp>> has internal linkage, and hence clang-tidy is right to flag this.

However, according to https://stackoverflow.com/a/48078494/627587, it appears that the rule doesn't actually apply, and so clang-tidy would in fact be wrong to flag this. Perhaps clang-tidy doesn't implement the resolution of CWG1713?

Also, one way to know for sure would be to look at the LLVM bitcode emitted, and confirm that __is_reverse_view<reverse_view<_Tp>> has linkoncde_odr linkage. If so, then clang-tidy would definitely be wrong to flag this.

This revision is now accepted and ready to land.Jan 31 2022, 5:56 PM
Quuxplusone accepted this revision.Feb 1 2022, 8:37 AM
Quuxplusone added inline comments.
libcxx/include/__iterator/iter_move.h
76

PSA: This will merge-conflict when rebased.

libcxx/include/__ranges/reverse_view.h
117

My understanding is that the variables instantiated from these templates behave the same as any other variables instantiated from templates — they shouldn't need inline for correctness, any more than a variable template (or function template) needs inline for correctness.
However, for consistency with the entire rest of the library, I think it would be a good idea to make these inline constexpr bool throughout. The STL uses inline constexpr bool for its own type-trait variables; even if they had no reason to do that originally, we certainly have no reason to innovate here. (Economist's $100 Bill blog post. :))
So I'm in favor of adding inline.

Also, in __ranges/join_view.h, I would change
constexpr bool __use_const = to static constexpr bool _UseConst = for consistency with some superficially similar code in subrange and reverse_view.

libcxx/include/cstddef
159

Suggest adding a blank line before this one.

This revision was landed with ongoing or failed builds.Feb 1 2022, 9:19 AM
This revision was automatically updated to reflect the committed changes.
philnik marked 4 inline comments as done.
philnik added inline comments.Feb 1 2022, 9:28 AM
libcxx/include/__ranges/reverse_view.h
117

This is now #53519. I'll make a PR later to add inline to the constexpr variables.