Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6c73eb

Browse files
H-G-Hristovphilnik777Zingam
authored
[libc++][docs] Update [[nodiscard]] coding guidelines (llvm#178384)
as requested in llvm#176936 (review) Clarifies when not to apply `[[nodiscard]]`. https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant --------- Co-authored-by: Nikolas Klauser <[email protected]> Co-authored-by: Hristo Hristov <[email protected]>
1 parent 47fb7cd commit e6c73eb

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

libcxx/docs/CodingGuidelines.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ have a recommended practice where to put them, so libc++ applies it whenever it
175175
This protects programmers from assuming too much about how the internals of a function work, making code more robust
176176
in the presence of future optimizations.
177177

178-
``[[nodiscard]]`` should not be applied to conversion functions because Clang already diagnoses unused cast results.
178+
``[[nodiscard]]`` should not be applied to functions if Clang already diagnoses unused results, for example:
179+
- conversion functions
180+
- equality operators
181+
- relational operators
179182

180183
Applications of ``[[nodiscard]]`` are code like any other code, so we aim to test them on public interfaces. This can be
181184
done with a ``.verify.cpp`` test. Many examples are available. Just look for tests with the suffix

0 commit comments

Comments
 (0)