Closed
Description
Follow up commits 41e5469, db63152 and 533b62d
by also making prefix increment and decrement not [[nodiscard]]
.
See #231 (comment):
I might have an use case for marking an ignorable output on a function declaration.
Consider https://compiler-explorer.com/z/r6sq4nGM1,
generated from https://cpp2.godbolt.org/z/K3v7xWeav.The
iterator::operator++
returnsthis
.
MSVC and GCC warn on the unused result of the compiler rewrite of the range for statement.iterator: @struct @ordered type = { operator*: (this) -> i32 = 0; operator++: (this) -> forward iterator = this; } range: @struct type = { begin: (this) -> iterator = (); end: (this) -> iterator = (); } main: () = { for range() do (x) _ = x; }
main.cpp2: In function 'int main()': main.cpp2:10:31: error: ignoring return value of 'const iterator& iterator::operator++() const', declared with attribute 'nodiscard' [-Werror=unused-result] 10 | for range() do (x) _ = x; | ^ main.cpp2:3:22: note: declared here 3 | operator++: (this) -> forward iterator = this; | ^~~~~~~~ cc1plus: some warnings being treated as errors