On 09/04/2013 05:24 AM, Benjamin Smedberg wrote:
>> MOZ_OVERRIDE implies virtual, you get a compile error when you put
>> MOZ_OVERRIDE on a non virtual
> It does? That surprises me (it certainly wasn't the original intent of
> NS_OVERRIDE). There are certainly cases where we want to override non-virtual
> methods with an identical signature.
C++11 override functionality only works on virtual methods. Agreed it's
somewhat unfortunate it's only on virtual methods -- else I'd have used it on
all the deleted methods in js/src/vm/String.h -- but that's how the language
works. We could of course add a new macro, plugging into static analysis, if
we wanted inherited-signature-matching functionality that worked on
non-virtuals.
Making virtual mandatory, and MOZ_OVERRIDE mandatory when applicable (to
slightly expand this thread's scope), sounds good to me.
The only edge case is if you have a template class inheriting from a
template-selected base, and the template class has a method that's virtual
depending on the selected base class:
template<class Base>
struct Foo : public Base
{
void fun() {}
};
struct B1 { virtual void fun(); };
struct B2 { void fun(); };
Foo<B1>().fun(); // virtual
Foo<B2>().fun(); // non-virtual
There's probably a use case for this. SecurityWrapper is probably close but no
cigar; nothing closer springs immediately to mind. This case would preclude
adding virtual or MOZ_OVERRIDE to Foo::fun's declaration -- probably a bridge
to cross if we get to it, of course.
Jeff
_______________________________________________
dev-platform mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-platform