Skip to content

Commit ab62cfd

Browse files
committed
Use static_cast
1 parent d7add33 commit ab62cfd

File tree

3 files changed

+41
-55
lines changed

3 files changed

+41
-55
lines changed

libcxx/src/include/overridable_function.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@
6060

6161
_LIBCPP_BEGIN_NAMESPACE_STD
6262

63-
template <class _Func>
64-
_LIBCPP_HIDE_FROM_ABI constexpr _Func* __overload_of(_Func* f) {
65-
return f;
66-
}
67-
6863
template <auto _Func>
6964
_LIBCPP_HIDE_FROM_ABI constexpr bool __is_function_overridden();
7065

@@ -78,8 +73,8 @@ _LIBCPP_END_NAMESPACE_STD
7873
extern __typeof(symbol##_impl__) name __attribute__((weak_import)); \
7974
_LIBCPP_BEGIN_NAMESPACE_STD \
8075
template <> \
81-
constexpr bool __is_function_overridden<__overload_of<type arglist>(name)>() { \
82-
return __overload_of<type arglist>(name) != symbol##_impl__; \
76+
constexpr bool __is_function_overridden<static_cast<type(*) arglist>(name)>() { \
77+
return static_cast<type(*) arglist>(name) != symbol##_impl__; \
8378
} \
8479
_LIBCPP_END_NAMESPACE_STD \
8580
type symbol##_impl__ arglist
@@ -88,11 +83,6 @@ _LIBCPP_END_NAMESPACE_STD
8883

8984
_LIBCPP_BEGIN_NAMESPACE_STD
9085

91-
template <class _Func>
92-
_LIBCPP_HIDE_FROM_ABI constexpr _Func* __overload_of(_Func* f) {
93-
return f;
94-
}
95-
9686
template <auto _Func>
9787
_LIBCPP_HIDE_FROM_ABI constexpr bool __is_function_overridden();
9888

@@ -104,8 +94,8 @@ _LIBCPP_END_NAMESPACE_STD
10494
[[gnu::weak, gnu::alias(_LIBCPP_TOSTRING(symbol##_impl__))]] type name arglist; \
10595
_LIBCPP_BEGIN_NAMESPACE_STD \
10696
template <> \
107-
constexpr bool __is_function_overridden<__overload_of<type arglist>(name)>() { \
108-
return __overload_of<type arglist>(name) != symbol##_impl__; \
97+
constexpr bool __is_function_overridden<static_cast<type(*) arglist>(name)>() { \
98+
return static_cast<type(*) arglist>(name) != symbol##_impl__; \
10999
} \
110100
_LIBCPP_END_NAMESPACE_STD \
111101
type symbol##_impl__ arglist

libcxx/src/new.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void* operator_new_impl(std::size_t size) {
4343
return p;
4444
}
4545

46-
_LIBCPP_OVERRIDABLE_FUNCTION(_Znmw, void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
46+
_LIBCPP_OVERRIDABLE_FUNCTION(_Znwm, void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
4747
void* p = operator_new_impl(size);
4848
if (p == nullptr)
4949
__throw_bad_alloc_shim();
@@ -54,7 +54,7 @@ _LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
5454
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
5555
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
5656
_LIBCPP_ASSERT_SHIM(
57-
!std::__is_function_overridden<std::__overload_of<void*(std::size_t)>(&operator new)>(),
57+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t)>(&operator new)>(),
5858
"libc++ was configured with exceptions disabled and `operator new(size_t)` has been overridden, "
5959
"but `operator new(size_t, nothrow_t)` has not been overridden. This is problematic because "
6060
"`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 {
8282
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
8383
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
8484
_LIBCPP_ASSERT_SHIM(
85-
!std::__is_function_overridden<std::__overload_of<void*(std::size_t)>(&operator new[])>(),
85+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t)>(&operator new[])>(),
8686
"libc++ was configured with exceptions disabled and `operator new[](size_t)` has been overridden, "
8787
"but `operator new[](size_t, nothrow_t)` has not been overridden. This is problematic because "
8888
"`operator new[](size_t, nothrow_t)` must call `operator new[](size_t)`, which will terminate in case "
@@ -148,7 +148,7 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
148148
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
149149
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
150150
_LIBCPP_ASSERT_SHIM(
151-
!std::__is_function_overridden<std::__overload_of<void*(std::size_t, std::align_val_t)>(&operator new)>(),
151+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)>(),
152152
"libc++ was configured with exceptions disabled and `operator new(size_t, align_val_t)` has been overridden, "
153153
"but `operator new(size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
154154
"`operator new(size_t, align_val_t, nothrow_t)` must call `operator new(size_t, align_val_t)`, which will "
@@ -169,15 +169,13 @@ _LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const s
169169
}
170170

171171
_LIBCPP_OVERRIDABLE_FUNCTION(_ZnamSt11align_val_t, void*, operator new[], (size_t size, std::align_val_t alignment))
172-
_THROW_BAD_ALLOC {
173-
return ::operator new(size, alignment);
174-
}
172+
_THROW_BAD_ALLOC { return ::operator new(size, alignment); }
175173

176174
_LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
177175
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
178176
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
179177
_LIBCPP_ASSERT_SHIM(
180-
!std::__is_function_overridden<std::__overload_of<void*(std::size_t, std::align_val_t)>(&operator new[])>(),
178+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])>(),
181179
"libc++ was configured with exceptions disabled and `operator new[](size_t, align_val_t)` has been overridden, "
182180
"but `operator new[](size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
183181
"`operator new[](size_t, align_val_t, nothrow_t)` must call `operator new[](size_t, align_val_t)`, which will "

libcxxabi/src/stdlib_new_delete.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,63 +63,63 @@ static void* operator_new_impl(std::size_t size) {
6363
return p;
6464
}
6565

66-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new(std::size_t size) _THROW_BAD_ALLOC {
66+
_LIBCPP_OVERRIDABLE_FUNCTION(_Znwm, void*, operator new, (std::size_t size)) _THROW_BAD_ALLOC {
6767
void* p = operator_new_impl(size);
6868
if (p == nullptr)
6969
__throw_bad_alloc_shim();
7070
return p;
7171
}
7272

7373
_LIBCPP_WEAK void* operator new(size_t size, const std::nothrow_t&) noexcept {
74-
#ifdef _LIBCPP_HAS_NO_EXCEPTIONS
75-
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
74+
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
75+
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
7676
_LIBCPP_ASSERT_SHIM(
77-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new)),
77+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t)>(&operator new)>(),
7878
"libc++ was configured with exceptions disabled and `operator new(size_t)` has been overridden, "
7979
"but `operator new(size_t, nothrow_t)` has not been overridden. This is problematic because "
8080
"`operator new(size_t, nothrow_t)` must call `operator new(size_t)`, which will terminate in case "
8181
"it fails to allocate, making it impossible for `operator new(size_t, nothrow_t)` to fulfill its "
8282
"contract (since it should return nullptr upon failure). Please make sure you override "
8383
"`operator new(size_t, nothrow_t)` as well.");
84-
# endif
84+
# endif
8585

8686
return operator_new_impl(size);
87-
#else
87+
# else
8888
void* p = nullptr;
8989
try {
9090
p = ::operator new(size);
9191
} catch (...) {
9292
}
9393
return p;
94-
#endif
94+
# endif
9595
}
9696

97-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void* operator new[](size_t size) _THROW_BAD_ALLOC {
97+
_LIBCPP_OVERRIDABLE_FUNCTION(_Znam, void*, operator new[], (size_t size)) _THROW_BAD_ALLOC {
9898
return ::operator new(size);
9999
}
100100

101101
_LIBCPP_WEAK void* operator new[](size_t size, const std::nothrow_t&) noexcept {
102-
#ifdef _LIBCPP_HAS_NO_EXCEPTIONS
103-
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
102+
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
103+
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
104104
_LIBCPP_ASSERT_SHIM(
105-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t)>(&operator new[])),
105+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t)>(&operator new[])>(),
106106
"libc++ was configured with exceptions disabled and `operator new[](size_t)` has been overridden, "
107107
"but `operator new[](size_t, nothrow_t)` has not been overridden. This is problematic because "
108108
"`operator new[](size_t, nothrow_t)` must call `operator new[](size_t)`, which will terminate in case "
109109
"it fails to allocate, making it impossible for `operator new[](size_t, nothrow_t)` to fulfill its "
110110
"contract (since it should return nullptr upon failure). Please make sure you override "
111111
"`operator new[](size_t, nothrow_t)` as well.");
112-
# endif
112+
# endif
113113

114114
return operator_new_impl(size);
115-
#else
115+
# else
116116
void* p = nullptr;
117117
try {
118118
p = ::operator new[](size);
119119
} catch (...) {
120120
}
121121
return p;
122-
#endif
122+
# endif
123123
}
124124

125125
_LIBCPP_WEAK void operator delete(void* ptr) noexcept { std::free(ptr); }
@@ -134,7 +134,7 @@ _LIBCPP_WEAK void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
134134

135135
_LIBCPP_WEAK void operator delete[](void* ptr, size_t) noexcept { ::operator delete[](ptr); }
136136

137-
#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
137+
# if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
138138

139139
static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) {
140140
if (size == 0)
@@ -156,66 +156,64 @@ static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignm
156156
return p;
157157
}
158158

159-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
160-
operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
159+
_LIBCPP_OVERRIDABLE_FUNCTION(_ZnwmSt11align_val_t, void*, operator new, (std::size_t size, std::align_val_t alignment))
160+
_THROW_BAD_ALLOC {
161161
void* p = operator_new_aligned_impl(size, alignment);
162162
if (p == nullptr)
163163
__throw_bad_alloc_shim();
164164
return p;
165165
}
166166

167167
_LIBCPP_WEAK void* operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
168-
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
169-
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
168+
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
169+
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
170170
_LIBCPP_ASSERT_SHIM(
171-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)),
171+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new)>(),
172172
"libc++ was configured with exceptions disabled and `operator new(size_t, align_val_t)` has been overridden, "
173173
"but `operator new(size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
174174
"`operator new(size_t, align_val_t, nothrow_t)` must call `operator new(size_t, align_val_t)`, which will "
175175
"terminate in case it fails to allocate, making it impossible for `operator new(size_t, align_val_t, nothrow_t)` "
176176
"to fulfill its contract (since it should return nullptr upon failure). Please make sure you override "
177177
"`operator new(size_t, align_val_t, nothrow_t)` as well.");
178-
# endif
178+
# endif
179179

180180
return operator_new_aligned_impl(size, alignment);
181-
# else
181+
# else
182182
void* p = nullptr;
183183
try {
184184
p = ::operator new(size, alignment);
185185
} catch (...) {
186186
}
187187
return p;
188-
# endif
188+
# endif
189189
}
190190

191-
_LIBCPP_MAKE_OVERRIDABLE_FUNCTION_DETECTABLE _LIBCPP_WEAK void*
192-
operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
193-
return ::operator new(size, alignment);
194-
}
191+
_LIBCPP_OVERRIDABLE_FUNCTION(_ZnamSt11align_val_t, void*, operator new[], (size_t size, std::align_val_t alignment))
192+
_THROW_BAD_ALLOC { return ::operator new(size, alignment); }
195193

196194
_LIBCPP_WEAK void* operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept {
197-
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
198-
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
195+
# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
196+
# if _LIBCPP_CAN_DETECT_OVERRIDDEN_FUNCTION
199197
_LIBCPP_ASSERT_SHIM(
200-
!std::__is_function_overridden(static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])),
198+
!std::__is_function_overridden<static_cast<void* (*)(std::size_t, std::align_val_t)>(&operator new[])>(),
201199
"libc++ was configured with exceptions disabled and `operator new[](size_t, align_val_t)` has been overridden, "
202200
"but `operator new[](size_t, align_val_t, nothrow_t)` has not been overridden. This is problematic because "
203201
"`operator new[](size_t, align_val_t, nothrow_t)` must call `operator new[](size_t, align_val_t)`, which will "
204202
"terminate in case it fails to allocate, making it impossible for `operator new[](size_t, align_val_t, "
205203
"nothrow_t)` to fulfill its contract (since it should return nullptr upon failure). Please make sure you "
206204
"override "
207205
"`operator new[](size_t, align_val_t, nothrow_t)` as well.");
208-
# endif
206+
# endif
209207

210208
return operator_new_aligned_impl(size, alignment);
211-
# else
209+
# else
212210
void* p = nullptr;
213211
try {
214212
p = ::operator new[](size, alignment);
215213
} catch (...) {
216214
}
217215
return p;
218-
# endif
216+
# endif
219217
}
220218

221219
_LIBCPP_WEAK void operator delete(void* ptr, std::align_val_t) noexcept { std::__libcpp_aligned_free(ptr); }

0 commit comments

Comments
 (0)