[libcxx-commits] [libcxx] [libc++][docs] Update `[[nodiscard]]` coding guide lines (PR #178384)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 28 01:23:07 PST 2026


https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/178384

as suggested in https://github.com/llvm/llvm-project/pull/176936#pullrequestreview-3706775444

>From bfeaf23226ae50f0b62105b1bdf0d68e3c35abb6 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Wed, 28 Jan 2026 11:22:45 +0200
Subject: [PATCH] [libc++][docs] Update `[[nodiscard]]` coding guide lines

as suggested in https://github.com/llvm/llvm-project/pull/176936#pullrequestreview-3706775444
---
 libcxx/docs/CodingGuidelines.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libcxx/docs/CodingGuidelines.rst b/libcxx/docs/CodingGuidelines.rst
index 97e6feef9d79b..2ebff9b1f8f33 100644
--- a/libcxx/docs/CodingGuidelines.rst
+++ b/libcxx/docs/CodingGuidelines.rst
@@ -165,7 +165,9 @@ 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.
+``[[nodiscard]]`` should not be applied to functions if Clang already diagnoses these cases, such as:
+- conversion functions because Clang already diagnoses unused cast results.
+- relational and equality operators because Clang already diagnoses unused results.
 
 Applications of ``[[nodiscard]]`` are code like any other code, so we aim to test them on public interfaces. This can be
 done with a ``.verify.cpp`` test. Many examples are available. Just look for tests with the suffix



More information about the libcxx-commits mailing list