Skip to content

Conversation

@H-G-Hristov
Copy link
Contributor

[[nodiscard]] should be applied to functions where discarding the return value is most likely a correctness issue.

@H-G-Hristov H-G-Hristov changed the title [libc++][math] Adding [[nodicard]] [libc++][cmath] Adding [[nodicard]] Dec 11, 2025
@github-actions
Copy link

github-actions bot commented Dec 11, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@H-G-Hristov H-G-Hristov force-pushed the hgh/libcxx/nodiscard-to-math branch 5 times, most recently from ecba760 to bdd1fb7 Compare December 11, 2025 18:24
Comment on lines 248 to 250
std::modf(0.F, 0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::modf(0., 0); // expected-warning-re 0-1 {{ignoring return value of function declared with {{.*}} attribute}}
std::modf(0.L, 0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's also reasonable to introduce float, double, and long double variables for these. Although this looks a bit messy to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

I am not sure if my current solution for the double overloads is correct: "expected-warning-re 0-1".

@H-G-Hristov H-G-Hristov force-pushed the hgh/libcxx/nodiscard-to-math branch from bdd1fb7 to 99715d3 Compare December 12, 2025 05:13
`[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue.

- https://libcxx.llvm.org/CodingGuidelines.htm
- https://wg21.link/c.math
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants