Adding [[nodiscard]] to functions is a conforming extension and done extensively in the MSVC STL.
Details
- Reviewers
ldionne Mordante var-const EricWF - Group Reviewers
Restricted Project - Commits
- rG3c355e288188: [libc++] Enable [[nodiscard]] extensions by default
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libcxx/docs/UsingLibcxx.rst | ||
---|---|---|
358–359 | This needs to read "can be disabled by defining `_LIBCPP_DISABLE_NODISCARD`" (note disable, not enable in the macro identifier) |
If we want to move forward with this patch, we're missing a bunch of changes. Please grep for _LIBCPP_ENABLE_NODISCARD in the codebase.
Once you've re-uploaded, I'll run a build internally to give us an idea of how the impact it might have on users. I suggest we discuss this once we have more data in hand.
BTW, if we find out that it doesn't break much code, and if we all agree that it's useful to catch bugs, then perhaps it doesn't make sense to provide an escape hatch at all.
libcxx/include/__config | ||
---|---|---|
883 | This whole thing is really confusing, and I think we need to clean it up. We have: _LIBCPP_DISABLE_NODISCARD _LIBCPP_DISABLE_NODISCARD_EXT _LIBCPP_DISABLE_NODISCARD_AFTER_CXX17 I don't understand why we have all that. We should only have one knob: _LIBCPP_DISABLE_NODISCARD_EXT, which would disable the nodiscards that we added as an extension. |
libcxx/docs/UsingLibcxx.rst | ||
---|---|---|
357–358 | Let's break the line here. | |
libcxx/include/__config | ||
889 | I think this is what we mean:
| |
892 | (not attached to any particular line) I think we need to go through all of our tests for nodiscard. Many of them will currently be marked as // UNSUPPORTED: c++03, c++11, c++14. Instead, they should be changed to: // UNSUPPORTED: (c++03 || c++11 || c++14) && !stdlib=libc++ so that we gain coverage for this newly added behavior. |
@cjdb You finally had your way :-)
I think this is a good change, the only things this uncovered when I tested in an internal build were actual bugs.
Pinging vendors for awareness, since this may start breaking builds that compile with -Werror.
Let's break the line here.