LibWeb/DOM: Work around GCC 14 warning on always true is<T>()

GCC 14 emits a warning when an always succeeding `dynamic_cast`'s return
value is compared to NULL inside the `AK::is<T>(U)` template when `T` ==
`U`.

While warning on tautological `is` calls seems useful, it's a bit
awkward when it comes from a function template where the cast may fail
in some instantiation. There is a GCC bug open for it:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115664

Work around the warning by performing the algorithm on the base type
(`EventTarget`), with a wrapper that casts it to the more specialized
input type.
This commit is contained in:
Daniel Bertalan 2024-07-18 23:56:52 +02:00 committed by Andreas Kling
commit 31eb0ed938
Notes: sideshowbarker 2024-07-19 21:36:17 +09:00

View file

@ -13,8 +13,7 @@
namespace Web::DOM {
// https://dom.spec.whatwg.org/#retarget
template<typename T>
T* retarget(T* a, T* b)
inline EventTarget* retarget_impl(EventTarget* a, EventTarget* b)
{
// To retarget an object A against an object B, repeat these steps until they return an object:
for (;;) {
@ -39,4 +38,11 @@ T* retarget(T* a, T* b)
}
}
// https://dom.spec.whatwg.org/#retarget
template<typename T>
T* retarget(T* a, T* b)
{
return static_cast<T*>(retarget_impl(a, b));
}
}