[libcxx-commits] [PATCH] D141321: [libc++] Add [[clang::lifetimebound]] attribute to std::forward and friends

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 13 09:28:53 PST 2023


ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

In D141321#4048177 <https://reviews.llvm.org/D141321#4048177>, @aaron.ballman wrote:

> I think trying to stay in sync is probably the right approach, but I don't have good ideas about how to automatically catch differences. However, I don't expect to make a lot of changes to these signatures, so maybe we don't need something to catch differences. I suspect the correct way to do this in Clang is to modify `Builtins.def` to add a new encoding for lifetime bound to the list of attributes, and then update `ASTContext::GetBuiltinType()`/`Sema::ActOnFunctionDeclarator()` to properly add the attribute where needed.

Actually, I think we do have a way to make sure that they stay in sync, at least for the aspects of it that we care about. We have our tests, and they will fail if somehow Clang doesn't do the right thing! It seems to do the right thing right now, since the tests are passing. IDK how that works, but oh well.



================
Comment at: libcxx/include/__utility/forward_like.h:37
 template <class _Tp, class _Up>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto forward_like(_Up&& __ux) noexcept -> _ForwardLike<_Tp, _Up> {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto forward_like(_LIBCPP_LIFETIMEBOUND _Up&& __ux) noexcept
+    -> _ForwardLike<_Tp, _Up> {
----------------
philnik wrote:
> Mordante wrote:
> > Should this extension be documented, like we do with `[[nodiscard]]`?
> I'm not convinced we should list the `[[nodiscard]]` decorated functions. As we extend the use of these kinds of macros the lists become long and I don't see why anybody who is actually interested in that list. Users are interested in getting warnings from the compiler, not which functions have some specific attribute. We also don't document which symbols are marked `[[clang::preferred_name]]`.
Yeah, I'd agree with dropping the list of `[[nodiscard]]` extensions in the docs, but please make sure they are all marked with `_LIBCPP_NODISCARD_EXT` so we can find them. Having the actual list in the documentation has little value and it will only get out of sync.

That should be done in a separate patch, obv.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141321/new/

https://reviews.llvm.org/D141321



More information about the libcxx-commits mailing list