-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Mark string functions as [[nodiscard]] #166524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions ,cpp -- libcxx/include/string libcxx/test/libcxx/diagnostics/string.nodiscard.verify.cpp libcxx/test/libcxx/strings/basic.string/nonnull.verify.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/libcxx/include/string b/libcxx/include/string
index cf2208fb2..79da203cf 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -1269,7 +1269,8 @@ public:
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT {
return reverse_iterator(end());
}
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT {
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator
+ rbegin() const _NOEXCEPT {
return const_reverse_iterator(end());
}
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT {
@@ -1772,8 +1773,8 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
# if _LIBCPP_STD_VER <= 20
- [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string
- substr(size_type __pos = 0, size_type __n = npos) const {
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string substr(size_type __pos = 0, size_type __n = npos) const {
return basic_string(*this, __pos, __n);
}
# else
@@ -2100,7 +2101,8 @@ public:
return !empty() && _Traits::eq(front(), __c);
}
- [[__nodiscard__]] constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
+ [[__nodiscard__]] constexpr _LIBCPP_HIDE_FROM_ABI bool
+ starts_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
return starts_with(__self_view(__s));
}
@@ -2114,7 +2116,8 @@ public:
return !empty() && _Traits::eq(back(), __c);
}
- [[__nodiscard__]] constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
+ [[__nodiscard__]] constexpr _LIBCPP_HIDE_FROM_ABI bool
+ ends_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
return ends_with(__self_view(__s));
}
# endif
|
|
@philnik777 I have a related off-topic question. The coding guidelines are quite clear about applying |
55eebcd to
93f64f1
Compare
The entire reason for having the guideline was that we want to apply
Some math functions should be marked
That would be great. |
…card]]` ...according to Coding Guidelines: - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant - llvm#166524 (comment)
…card]]` ...according to Coding Guidelines: - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant - llvm#166524 (comment)
…card]]` ...according to Coding Guidelines: - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant - llvm#166524 (comment)
…card]]` ...according to Coding Guidelines: - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant - llvm#166524 (comment)
…card]]` ...according to Coding Guidelines: - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant - llvm#166524 (comment)
This applies
[[nodiscard]]according to our coding guidelines tobasic_string.