[libcxx-commits] [libcxx] [libcxx] Use alias for detecting overriden function (PR #114961)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 5 01:48:43 PST 2024
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 0b8fec69464ce4a7e759137b091a6b7500458f36 02cffe21d36f820fe88e8c900738dbd526a998b0 --extensions h,cpp -- libcxx/src/include/overridable_function.h libcxx/src/new.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/src/include/overridable_function.h b/libcxx/src/include/overridable_function.h
index 09487d84df..5f892ef936 100644
--- a/libcxx/src/include/overridable_function.h
+++ b/libcxx/src/include/overridable_function.h
@@ -60,7 +60,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD
template <typename _Func>
-constexpr _Func* __overload_of(_Func* f) { return f; }
+constexpr _Func* __overload_of(_Func* f) {
+ return f;
+}
template <auto _Func>
constexpr bool __is_function_overridden();
@@ -68,25 +70,27 @@ constexpr bool __is_function_overridden();
_LIBCPP_END_NAMESPACE_STD
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
-# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
- extern "C" type symbol##_impl__ arglist; \
- __asm__(".globl _" _LIBCPP_TOSTRING(symbol)); \
- __asm__(".set _" _LIBCPP_TOSTRING(symbol) ", _" _LIBCPP_TOSTRING(symbol##_impl__)); \
- extern __typeof(symbol##_impl__) name __attribute__((weak_import)); \
- _LIBCPP_BEGIN_NAMESPACE_STD \
- template <> \
- constexpr bool __is_function_overridden<__overload_of<type arglist>(name)>() { \
- return __overload_of<type arglist>(name) != symbol##_impl__; \
- } \
- _LIBCPP_END_NAMESPACE_STD \
- type symbol##_impl__ arglist
+# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
+ extern "C" type symbol##_impl__ arglist; \
+ __asm__(".globl _" _LIBCPP_TOSTRING(symbol)); \
+ __asm__(".set _" _LIBCPP_TOSTRING(symbol) ", _" _LIBCPP_TOSTRING(symbol##_impl__)); \
+ extern __typeof(symbol##_impl__) name __attribute__((weak_import)); \
+ _LIBCPP_BEGIN_NAMESPACE_STD \
+ template <> \
+ constexpr bool __is_function_overridden<__overload_of<type arglist>(name)>() { \
+ return __overload_of<type arglist>(name) != symbol##_impl__; \
+ } \
+ _LIBCPP_END_NAMESPACE_STD \
+ type symbol##_impl__ arglist
#elif defined(_LIBCPP_OBJECT_FORMAT_ELF)
_LIBCPP_BEGIN_NAMESPACE_STD
template <typename _Func>
-constexpr _Func* __overload_of(_Func* f) { return f; }
+constexpr _Func* __overload_of(_Func* f) {
+ return f;
+}
template <auto _Func>
constexpr bool __is_function_overridden();
@@ -94,22 +98,21 @@ constexpr bool __is_function_overridden();
_LIBCPP_END_NAMESPACE_STD
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 1
-# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
- extern "C" type symbol##_impl__ arglist; \
- [[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__))]] type name arglist; \
- _LIBCPP_BEGIN_NAMESPACE_STD \
- template <> \
- constexpr bool __is_function_overridden<__overload_of<type arglist>(name)>() { \
- return __overload_of<type arglist>(name) != symbol##_impl__; \
- } \
- _LIBCPP_END_NAMESPACE_STD \
- type symbol##_impl__ arglist
+# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
+ extern "C" type symbol##_impl__ arglist; \
+ [[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__))]] type name arglist; \
+ _LIBCPP_BEGIN_NAMESPACE_STD \
+ template <> \
+ constexpr bool __is_function_overridden<__overload_of<type arglist>(name)>() { \
+ return __overload_of<type arglist>(name) != symbol##_impl__; \
+ } \
+ _LIBCPP_END_NAMESPACE_STD \
+ type symbol##_impl__ arglist
#else
# define _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION 0
-# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) \
- _LIBCPP_WEAK type name arglist
+# define _LIBCPP_OVERRIDABLE_FUNCTION(symbol, type, name, arglist) _LIBCPP_WEAK type name arglist
#endif
diff --git a/libcxx/src/new.cpp b/libcxx/src/new.cpp
index 3e99aed455..f5435df028 100644
--- a/libcxx/src/new.cpp
+++ b/libcxx/src/new.cpp
@@ -43,7 +43,7 @@ static void* operator_new_impl(std::size_t size) {
return p;
}
-_LIBCPP_OVERRIDABLE_FUNCTION(_Znmw, void *, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
+_LIBCPP_OVERRIDABLE_FUNCTION(_Znmw, void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
void* p = operator_new_impl(size);
if (p == nullptr)
__throw_bad_alloc_shim();
@@ -54,7 +54,7 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
_LIBCPP_ASSERT_SHIM(
- !std::__is_function_overridden<std::__overload_of<void* (std::size_t)>(&operator new)>(),
+ !std::__is_function_overridden<std::__overload_of<void*(std::size_t)>(&operator new)>(),
"libc++ was configured with exceptions disabled and `operator new(size_t)` has been overridden, "
"but `operator new(size_t, nothrow_t)` has not been overridden. This is problematic because "
"`operator new(size_t, nothrow_t)` must call `operator new(size_t)`, which will terminate in case "
@@ -82,7 +82,7 @@ _LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
_LIBCPP_ASSERT_SHIM(
- !std::__is_function_overridden<std::__overload_of<void* (std::size_t)>(&operator new[])>(),
+ !std::__is_function_overridden<std::__overload_of<void*(std::size_t)>(&operator new[])>(),
"libc++ was configured with exceptions disabled and `operator new[](size_t)` has been overridden, "
"but `operator new[](size_t, nothrow_t)` has not been overridden. This is problematic because "
"`operator new[](size_t, nothrow_t)` must call `operator new[](size_t)`, which will terminate in case "
@@ -137,8 +137,9 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
}
//_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
-//operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
-_LIBCPP_OVERRIDABLE_FUNCTION(_ZnwmSt11align_val_t, void*, operator new, (std::size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {
+// operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
+_LIBCPP_OVERRIDABLE_FUNCTION(_ZnwmSt11align_val_t, void*, operator new, (std::size_t size, std::align_val_t alignment))
+_THROW_BAD_ALLOC {
void* p = operator_new_aligned_impl(size, alignment);
if (p == nullptr)
__throw_bad_alloc_shim();
@@ -149,7 +150,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
_LIBCPP_ASSERT_SHIM(
- !std::__is_function_overridden<std::__overload_of<void* (std::size_t, std::align_val_t)>(&operator new)>(),
+ !std::__is_function_overridden<std::__overload_of<void*(std::size_t, std::align_val_t)>(&operator new)>(),
"libc++ was configured with exceptions disabled and `operator new(size_t, align_val_t)` has been overridden, "
"but `operator new(size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
"`operator new(size_t, align_val_t, nothrow_t)` must call `operator new(size_t, align_val_t)`, which will "
@@ -169,7 +170,8 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
# endif
}
-_LIBCPP_OVERRIDABLE_FUNCTION(_ZnamSt11align_val_t, void *, operator new[], (size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {
+_LIBCPP_OVERRIDABLE_FUNCTION(_ZnamSt11align_val_t, void*, operator new[], (size_t size, std::align_val_t alignment))
+_THROW_BAD_ALLOC {
return ::operator new(size, alignment);
}
@@ -177,7 +179,7 @@ _LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
_LIBCPP_ASSERT_SHIM(
- !std::__is_function_overridden<std::__overload_of<void* (std::size_t, std::align_val_t)>(&operator new[])>(),
+ !std::__is_function_overridden<std::__overload_of<void*(std::size_t, std::align_val_t)>(&operator new[])>(),
"libc++ was configured with exceptions disabled and `operator new[](size_t, align_val_t)` has been overridden, "
"but `operator new[](size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
"`operator new[](size_t, align_val_t, nothrow_t)` must call `operator new[](size_t, align_val_t)`, which will "
``````````
</details>
https://github.com/llvm/llvm-project/pull/114961
More information about the libcxx-commits
mailing list