-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[libc++] Clang-tidy enable modernize-use-nullptr. #76659
Merged
mordante
merged 1 commit into
main
from
users/mordante/clang-tidy_modernize-use-nullptr
Jan 17, 2024
Merged
[libc++] Clang-tidy enable modernize-use-nullptr. #76659
mordante
merged 1 commit into
main
from
users/mordante/clang-tidy_modernize-use-nullptr
Jan 17, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
the
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
label
Dec 31, 2023
@llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) ChangesClang-tidy 18 no longer has false positives with the spaceship operator. Note that I'm quite sure there are more occurrences in our headers that are not caught. Full diff: https://github.com/llvm/llvm-project/pull/76659.diff 3 Files Affected:
diff --git a/libcxx/.clang-tidy b/libcxx/.clang-tidy
index 214661789cd51a..ec7cab9b878ed9 100644
--- a/libcxx/.clang-tidy
+++ b/libcxx/.clang-tidy
@@ -15,6 +15,7 @@ Checks: >
modernize-loop-convert,
modernize-redundant-void-arg,
+ modernize-use-nullptr,
modernize-use-override,
readability-duplicate-include,
@@ -68,7 +69,6 @@ CheckOptions:
# modernize-use-default-member-init,
# modernize-use-equals-default,
# modernize-use-equals-delete,
-# modernize-use-nullptr,
# portability-restrict-system-includes,
# readability-function-cognitive-complexity,
# readability-implicit-bool-conversion,
diff --git a/libcxx/include/__atomic/is_always_lock_free.h b/libcxx/include/__atomic/is_always_lock_free.h
index fbbd4370749908..f928e79f70cea3 100644
--- a/libcxx/include/__atomic/is_always_lock_free.h
+++ b/libcxx/include/__atomic/is_always_lock_free.h
@@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
struct __libcpp_is_always_lock_free {
// __atomic_always_lock_free is available in all Standard modes
- static const bool __value = __atomic_always_lock_free(sizeof(_Tp), 0);
+ static const bool __value = __atomic_always_lock_free(sizeof(_Tp), nullptr);
};
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/locale b/libcxx/include/locale
index 70d22ff95e1ee1..9e97eb9f339533 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -3421,7 +3421,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() {
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() {
_LIBCPP_SUPPRESS_DEPRECATED_POP
- if (__cv_ == 0 || __bufptr_ == 0)
+ if (__cv_ == 0 || __bufptr_ == nullptr)
return traits_type::eof();
bool __initial = __read_mode();
char_type __1buf;
@@ -3478,7 +3478,7 @@ template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) {
_LIBCPP_SUPPRESS_DEPRECATED_POP
- if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) {
+ if (__cv_ != 0 && __bufptr_ && this->eback() < this->gptr()) {
if (traits_type::eq_int_type(__c, traits_type::eof())) {
this->gbump(-1);
return traits_type::not_eof(__c);
@@ -3496,7 +3496,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) {
_LIBCPP_SUPPRESS_DEPRECATED_POP
- if (__cv_ == 0 || __bufptr_ == 0)
+ if (__cv_ == 0 || !__bufptr_)
return traits_type::eof();
__write_mode();
char_type __1buf;
@@ -3588,7 +3588,7 @@ template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __om) {
int __width = __cv_->encoding();
- if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync())
+ if (__cv_ == 0 || !__bufptr_ || (__width <= 0 && __off != 0) || sync())
return pos_type(off_type(-1));
// __width > 0 || __off == 0, now check __way
if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
@@ -3601,7 +3601,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) {
- if (__cv_ == 0 || __bufptr_ == 0 || sync())
+ if (__cv_ == 0 || !__bufptr_ || sync())
return pos_type(off_type(-1));
if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
return pos_type(off_type(-1));
@@ -3611,7 +3611,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode
template <class _Codecvt, class _Elem, class _Tr>
int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() {
_LIBCPP_SUPPRESS_DEPRECATED_POP
- if (__cv_ == 0 || __bufptr_ == 0)
+ if (__cv_ == 0 || !__bufptr_)
return 0;
if (__cm_ & ios_base::out) {
if (this->pptr() != this->pbase())
|
ldionne
approved these changes
Dec 31, 2023
philnik777
approved these changes
Jan 1, 2024
mordante
force-pushed
the
users/mordante/switches_to_clang-tidy-18
branch
2 times, most recently
from
January 17, 2024 07:18
b3c567f
to
84c74e0
Compare
Base automatically changed from
users/mordante/switches_to_clang-tidy-18
to
main
January 17, 2024 07:18
Clang-tidy 18 no longer has false positives with the spaceship operator. Note that I'm quite sure there are more occurrences in our headers that are not caught.
mordante
force-pushed
the
users/mordante/clang-tidy_modernize-use-nullptr
branch
from
January 17, 2024 07:22
b28cb65
to
aca42e1
Compare
var-const
added a commit
to var-const/llvm-project
that referenced
this pull request
Jan 17, 2024
This reverts commit 020ea3e. This seems to break `test/libcxx/clang_tidy.gen.py/regex.sh.cpp` (in C++03 mode for some reason): ``` 2024-01-17T07:32:22.1759374Z # RUN: at line 12 2024-01-17T07:32:22.1773919Z clang-tidy-18 /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/libcxx/clang_tidy.gen.py/regex.sh.cpp --warnings-as-errors=* -header-filter=.* --config-file=/home/runner/_work/llvm-project/llvm-project/libcxx/.clang-tidy -- -Wweak-vtables -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -fno-modules 2024-01-17T07:32:22.1803227Z # executed command: clang-tidy-18 /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/libcxx/clang_tidy.gen.py/regex.sh.cpp '--warnings-as-errors=*' '-header-filter=.*' --config-file=/home/runner/_work/llvm-project/llvm-project/libcxx/.clang-tidy -- -Wweak-vtables -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -fno-modules 2024-01-17T07:32:22.1817757Z # .---command stdout------------ 2024-01-17T07:32:22.1820160Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:50: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1822498Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1823337Z # | | ^ 2024-01-17T07:32:22.1824052Z # | | nullptr 2024-01-17T07:32:22.1826651Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:53: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1829325Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1831137Z # | | ^ 2024-01-17T07:32:22.1831963Z # | | nullptr 2024-01-17T07:32:22.1834149Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:56: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1848711Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1849506Z # | | ^ 2024-01-17T07:32:22.1849997Z # | | nullptr 2024-01-17T07:32:22.1851528Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:59: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1853391Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1854277Z # | | ^ 2024-01-17T07:32:22.1854841Z # | | nullptr 2024-01-17T07:32:22.1856314Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:62: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1857768Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1858493Z # | | ^ 2024-01-17T07:32:22.1858998Z # | | nullptr 2024-01-17T07:32:22.1859503Z # `----------------------------- 2024-01-17T07:32:22.1859900Z # .---command stderr------------ 2024-01-17T07:32:22.1860259Z # | 43 warnings generated. 2024-01-17T07:32:22.1860710Z # | Suppressed 33 warnings (33 in non-user code). 2024-01-17T07:32:22.1861809Z # | Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. 2024-01-17T07:32:22.1862750Z # | 5 warnings treated as errors 2024-01-17T07:32:22.1863229Z # `----------------------------- 2024-01-17T07:32:22.1863622Z # error: command failed with exit status: 1 ``` (see https://github.com/llvm/llvm-project/actions/runs/7552394884/job/20561192096)
var-const
added a commit
that referenced
this pull request
Jan 17, 2024
…78409) This reverts commit 020ea3e. This seems to break `test/libcxx/clang_tidy.gen.py/regex.sh.cpp` (in C++03 mode for some reason): ``` 2024-01-17T07:32:22.1759374Z # RUN: at line 12 2024-01-17T07:32:22.1773919Z clang-tidy-18 /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/libcxx/clang_tidy.gen.py/regex.sh.cpp --warnings-as-errors=* -header-filter=.* --config-file=/home/runner/_work/llvm-project/llvm-project/libcxx/.clang-tidy -- -Wweak-vtables -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -fno-modules 2024-01-17T07:32:22.1803227Z # executed command: clang-tidy-18 /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/libcxx/clang_tidy.gen.py/regex.sh.cpp '--warnings-as-errors=*' '-header-filter=.*' --config-file=/home/runner/_work/llvm-project/llvm-project/libcxx/.clang-tidy -- -Wweak-vtables -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -fno-modules 2024-01-17T07:32:22.1817757Z # .---command stdout------------ 2024-01-17T07:32:22.1820160Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:50: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1822498Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1823337Z # | | ^ 2024-01-17T07:32:22.1824052Z # | | nullptr 2024-01-17T07:32:22.1826651Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:53: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1829325Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1831137Z # | | ^ 2024-01-17T07:32:22.1831963Z # | | nullptr 2024-01-17T07:32:22.1834149Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:56: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1848711Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1849506Z # | | ^ 2024-01-17T07:32:22.1849997Z # | | nullptr 2024-01-17T07:32:22.1851528Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:59: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1853391Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1854277Z # | | ^ 2024-01-17T07:32:22.1854841Z # | | nullptr 2024-01-17T07:32:22.1856314Z # | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__iterator/iterator_traits.h:124:62: error: use nullptr [modernize-use-nullptr,-warnings-as-errors] 2024-01-17T07:32:22.1857768Z # | 124 | static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; 2024-01-17T07:32:22.1858493Z # | | ^ 2024-01-17T07:32:22.1858998Z # | | nullptr 2024-01-17T07:32:22.1859503Z # `----------------------------- 2024-01-17T07:32:22.1859900Z # .---command stderr------------ 2024-01-17T07:32:22.1860259Z # | 43 warnings generated. 2024-01-17T07:32:22.1860710Z # | Suppressed 33 warnings (33 in non-user code). 2024-01-17T07:32:22.1861809Z # | Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. 2024-01-17T07:32:22.1862750Z # | 5 warnings treated as errors 2024-01-17T07:32:22.1863229Z # `----------------------------- 2024-01-17T07:32:22.1863622Z # error: command failed with exit status: 1 ``` (see https://github.com/llvm/llvm-project/actions/runs/7552394884/job/20561192096)
blueboxd
pushed a commit
to blueboxd/libcxx
that referenced
this pull request
Feb 7, 2024
Clang-tidy 18 no longer has false positives with the spaceship operator. Note that I'm quite sure there are more occurrences in our headers that are not caught. This relands llvm/llvm-project#76659 with fixes tested in llvm/llvm-project#78746. NOKEYCHECK=True GitOrigin-RevId: 5b7bb56a053702f7ed486aba1427454ec222bb36
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Clang-tidy 18 no longer has false positives with the spaceship operator. Note that I'm quite sure there are more occurrences in our headers that are not caught.