[libcxx-commits] [libcxx] [libc++] Diagnose passing null pointers to a bunch of APIs (PR #148585)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 14 01:37:57 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions ,h,cpp -- libcxx/test/libcxx/algorithms/specialized.algorithms/nonnull.verify.cpp libcxx/test/libcxx/input.output/iostream.format/print.fun/nonnull.verify.cpp libcxx/test/libcxx/strings/string.view/nonnull.verify.cpp libcxx/include/__config libcxx/include/__memory/construct_at.h libcxx/include/print libcxx/include/string libcxx/include/string_view libcxx/test/libcxx/strings/basic.string/nonnull.verify.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index a59e2f3bd..658269158 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -32,7 +32,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
-template <class _Tp, class... _Args, class = decltype(::new (std::declval<void*>()) _Tp(std::declval<_Args>()...))>
+template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>
_LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* _LIBCPP_DIAGNOSE_NULLPTR __location, _Args&&... __args) {
_LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at");
return ::new (static_cast<void*>(__location)) _Tp(std::forward<_Args>(__args)...);
diff --git a/libcxx/test/libcxx/algorithms/specialized.algorithms/nonnull.verify.cpp b/libcxx/test/libcxx/algorithms/specialized.algorithms/nonnull.verify.cpp
index 4bad90eb6..d79c4ce4c 100644
--- a/libcxx/test/libcxx/algorithms/specialized.algorithms/nonnull.verify.cpp
+++ b/libcxx/test/libcxx/algorithms/specialized.algorithms/nonnull.verify.cpp
@@ -13,10 +13,10 @@
#include <memory>
void func() {
- using Arr = int[1];
- int* const np = nullptr;
+ using Arr = int[1];
+ int* const np = nullptr;
Arr* const np2 = nullptr;
std::construct_at(np); // expected-warning {{null passed}}
std::destroy_at(np); // expected-warning {{null passed}}
- std::destroy_at(np2); // expected-warning {{null passed}}
+ std::destroy_at(np2); // expected-warning {{null passed}}
}
diff --git a/libcxx/test/libcxx/strings/string.view/nonnull.verify.cpp b/libcxx/test/libcxx/strings/string.view/nonnull.verify.cpp
index 0266bac4d..be3034abd 100644
--- a/libcxx/test/libcxx/strings/string.view/nonnull.verify.cpp
+++ b/libcxx/test/libcxx/strings/string.view/nonnull.verify.cpp
@@ -16,17 +16,17 @@
void func() {
const char* const np = nullptr;
- std::string_view str1(np); // expected-warning {{null passed}}
- str1 = np; // expected-warning {{null passed}}
- str1.find(np); // expected-warning {{null passed}}
- str1.rfind(np); // expected-warning {{null passed}}
- str1.find_first_of(np); // expected-warning {{null passed}}
- str1.find_last_of(np); // expected-warning {{null passed}}
- str1.find_first_not_of(np); // expected-warning {{null passed}}
- str1.find_last_not_of(np); // expected-warning {{null passed}}
- str1.compare(np); // expected-warning {{null passed}}
- str1.compare(0, 0, np); // expected-warning {{null passed}}
- (void)(str1 == np); // expected-warning {{null passed}}
+ std::string_view str1(np); // expected-warning {{null passed}}
+ str1 = np; // expected-warning {{null passed}}
+ str1.find(np); // expected-warning {{null passed}}
+ str1.rfind(np); // expected-warning {{null passed}}
+ str1.find_first_of(np); // expected-warning {{null passed}}
+ str1.find_last_of(np); // expected-warning {{null passed}}
+ str1.find_first_not_of(np); // expected-warning {{null passed}}
+ str1.find_last_not_of(np); // expected-warning {{null passed}}
+ str1.compare(np); // expected-warning {{null passed}}
+ str1.compare(0, 0, np); // expected-warning {{null passed}}
+ (void)(str1 == np); // expected-warning {{null passed}}
#if TEST_STD_VER >= 20
str1.starts_with(np); // expected-warning {{null passed}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/148585
More information about the libcxx-commits
mailing list