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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 5 01:24:11 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.
----------------
frederick-vs-ja wrote:

`operator bool()` is a conversion function so we don't need further generalization. `operator->()` is fairly tricky as its conventional usage is never discarding. I haven't come up with suitable wording for it.

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


More information about the libcxx-commits mailing list