From 31eb0ed938dff11dee7391a4f616f4132aa250c0 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Thu, 18 Jul 2024 23:56:52 +0200 Subject: [PATCH] LibWeb/DOM: Work around GCC 14 warning on always true `is()` GCC 14 emits a warning when an always succeeding `dynamic_cast`'s return value is compared to NULL inside the `AK::is(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. --- Userland/Libraries/LibWeb/DOM/Utils.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Utils.h b/Userland/Libraries/LibWeb/DOM/Utils.h index 3324187e723..5ba28e173da 100644 --- a/Userland/Libraries/LibWeb/DOM/Utils.h +++ b/Userland/Libraries/LibWeb/DOM/Utils.h @@ -13,8 +13,7 @@ namespace Web::DOM { // https://dom.spec.whatwg.org/#retarget -template -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 +T* retarget(T* a, T* b) +{ + return static_cast(retarget_impl(a, b)); +} + }