[libcxx-commits] [libcxx] [libc++] Revert undesired `[[nodiscard]]` added to conversion functions (PR #173658)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 4 21:19:09 PST 2026


================
@@ -165,6 +165,8 @@ have a recommended practice where to put them, so libc++ applies it whenever it
   This protects programmers from assuming too much about how the internals of a function work, making code more robust
   in the presence of future optimizations.
 
+``[[nodiscard]]`` should not be applied to conversion functions because Clang already diagnoses unused cast results.
----------------
H-G-Hristov wrote:

The above should probably be generalized also to "if there is a compiler diagnostic, we don't need `[[nodiscard]]` annotation" and then specific cases. WDYT?
I think we should document all cases where it "undesirable" to annotate as it would be easier to argue in a code review, see: https://github.com/llvm/llvm-project/pull/166717#discussion_r2599858318
For example:
`operator bool()`
`operator ->()`

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


More information about the libcxx-commits mailing list