diff --git a/AK/IntrusiveList.h b/AK/IntrusiveList.h index fb183a77f9..b5fd221bd7 100644 --- a/AK/IntrusiveList.h +++ b/AK/IntrusiveList.h @@ -27,6 +27,7 @@ #pragma once #include +#include namespace AK { @@ -269,7 +270,13 @@ inline typename IntrusiveList::ConstIterator IntrusiveList template inline T* IntrusiveList::node_to_value(IntrusiveListNode& node) { - return (T*)((char*)&node - ((char*)&(((T*)nullptr)->*member) - (char*)nullptr)); + // Note: Since this might seem odd, here's an explanation on what this function actually does: + // `node` is a reference that resides in some part of the actual value (of type T), the + // placement (i.e. offset) of which is described by the pointer-to-data-member parameter + // named `member`. + // This function effectively takes in the address of the data member, and returns the address + // of the value (of type T) holding that member. + return bit_cast(bit_cast(&node) - bit_cast(member)); } inline IntrusiveListNode::~IntrusiveListNode()