[Webkit-unassigned] [Bug 213278] IPC/Decoder.h and IPC/Encoder.h need every WTF::EnumTraits<> specialization included before they are included

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Jun 22 21:11:46 PDT 2020


https://bugs.webkit.org/show_bug.cgi?id=213278

--- Comment #4 from David Kilzer (:ddkilzer) <ddkilzer at webkit.org> ---
(In reply to Darin Adler from comment #2)
> It doesn’t really make logical sense that every specialization has to be
> included first. I think we have to more deeply understand why. Normally it’s
> when templates are expanded/used, not when they are included, that all the
> things they call have to be present. We probably have to get a more solid
> understanding of what creates this dependency.
> 
> We may change isValidEnum from a namespace-level function template to
> something different. Normally functions are specialized with overloading
> rather than specializing a template. That may be part of the problem here.
> Perhaps we can overload isValidEnum rather than specializing an isValidEnum
> function template. Another possibility is to use the traits pattern and have
> EnumValidityCheck be a class template with a static member function isValid.
> Not sure this solves the problem, but I think it might.

Okay, using pre-processed source, I've verified that if I don't #include <WebCore/ContextMenuItem.h> in Decoder.h/Encoder.h, then the specialized isValidEnum() function is included after it's needed in Decoder.h/Encoder.h when building Source/WebKit/Shared/WebContextMenuItemData.cpp.

I'm not sure how to turn your suggestion into code, though. I tried a first pass, but it seems much more complex than it should be (I didn't even try to compile it), and I don't see how it solves the #include order issue.  I'm probably doing it wrong, and figuring it out is going to take me much longer than it should to get it correct/working.  (I suspect my time could best be spent on other bugs, despite wanting to learn how to do this.)

This is what I wrote:


template<>
struct EnumValueChecker<false> {
    template<typename E, typename T>
    static constexpr bool isValid(T t)
    {
        static_assert(sizeof(T) >= sizeof(std::underlying_type_t<E>), "Integral type must be at least the size of the underlying enum type");

        return EnumValueChecker<T, typename EnumTraits<E>::values>::isValidEnum(t);
    }
};

template<>
struct EnumValueChecker<false> {
    template<typename E, typename T = bool>
    static constexpr bool isValid(T t)
    {
        return !t || t == 1;
    }
};

template<typename E, typename T>
constexpr bool isValidEnum(T t)
{
    return EnumValidityCheck<HasCustomIsValidEnum<E>::value>::isValid<E>(t);
}


I still think it requires an early #include, though.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20200623/27a7dc57/attachment.htm>


More information about the webkit-unassigned mailing list