[Webkit-unassigned] [Bug 70629] class X : public RefCounted<Y> should cause a compilation error

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Apr 27 06:50:56 PDT 2012


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


Caio Marcelo de Oliveira Filho <cmarcelo at webkit.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cmarcelo at webkit.org




--- Comment #1 from Caio Marcelo de Oliveira Filho <cmarcelo at webkit.org>  2012-04-27 06:50:56 PST ---
I've tried some solutions using traits and compile asserts without full success, I could prevent some wrong uses but not all. Unless we are willing to put a macro to include the check in the class X itself, I don't see how we can fully check by compile asserts.

The ideal solution would be to make RefCounted constructor private and make it friend to its template parameter.

template<typename T> class RefCounted : public RefCountedBase {
    friend T; // Note C++11 syntax.
    RefCounted() { ... }
    ...
};

But this support was added only in C++11. There are tricks that work for current GCC and MSVC that allow us to achieve it without C++11

template <typename T>
struct Identity {
    typedef T type;
};

template<typename T> class RefCounted : public RefCountedBase {
    friend class Identity<T>::type; // Apparently MSVC doesn't need 'class' here.
    RefCounted() { ... }
    ...
};

Is it worth it to add this prevention even if it can't cover all the compilers? My feeling is that if the check works in some EWSs, we could benefit even if the contributor compiler don't catch the problem.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list