[clang] [clang] Add the candiscard attribute to suppress nodiscard (PR #154943)

via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 24 19:49:48 PDT 2025


huixie90 wrote:

> > Thank you working on this! Can you explain why we introduce this new attribute in summary?
> 
> @yronglin Compiler support for this new attribute is required by @philnik777 before libc++ can mark its `std::expected` with the `[[nodiscard]]` attribute, as requested in #130656 and already done by Microsoft C++, LLVM itself (`llvm::Expected`) and Rust. This will bring libc++ up to snuff with other C++ implementations.
> 
> Personally I do not think this attribute will be used by programmers, it is just purely a requirement for fixing #130656.

The new attribute is meant to be used by end users. 

Right now, in the stl, there is no function that returns std::expected yet, so we don’t actually need to use the new attribute within the library. 

What we want is to mark the type std::expected nodiscard, but currently if a user (library writer) wants to create a function that returns std::expected, there is no way for the library writer to say “it is ok to discard the return value” and this new attribute is the right tool for those library writers (not for the Libc++ ourself)

https://github.com/llvm/llvm-project/pull/154943


More information about the cfe-commits mailing list