On 04/27/2015 12:48 PM, Ehsan Akhgari wrote: > I think we should > change it to require the usage of exactly one of these keywords per > *overridden* function: virtual, override, and final.
Let me attempt to clarify why the "exactly one" requirement here is important. (It's non-obvious.) This verbose function-signature... "virtual void foo() final override;" ...can be expressed as the following, without removing any strictness: "void foo() final" BUT, if we add back the "virtual" keyword, we *lose some strictness*. In other words, this is *not* equivalent to the versions above: "virtual void foo() final" Unless the formulations above, this version isn't guaranteed to override. The keywords "final override" can be viewed as redundant, but only if the virtual keyword is not present. This is because final implies virtual, and virtualness-without-an-explicit-virtual-keyword implies override. So final + lack-of-virtual-keyword implies override. Hence the "exactly one" requirement that ehsan is proposing (which Google has adopted). > * It makes it easier to determine what kind of function you are looking at > by just looking at its declaration. |virtual void foo();| means a virtual > function that is not overridden, |void foo() override;| means an overridden > virtual function, and |void foo() final;| means an overridden virtual > function that cannot be further overridden. After discussing briefly with ehsan on IRC -- let me clarify the language on this, since the word "overridden" is ambiguous here. (ehsan was mostly using it to mean "is an override of something else") I'll restate the three categories, with less ambiguous language: - |virtual void foo();| means a virtual function that is not an override of a superclass method. - |void foo() override;| means an overriding virtual function. - |void foo() final;| means an overriding virtual function that cannot be further overridden. > * It will allow us to remove NS_IMETHODIMP, and use NS_IMETHOD instead. (FWIW: This is because NS_METHODIMP expands to the exact same thing as NS_IMETHOD, minus the 'virtual' keyword: https://mxr.mozilla.org/mozilla-central/source/xpcom/base/nscore.h?rev=7e4e5e971d95&mark=96-97#96 So if we were to drop 'virtual' from NS_IMETHOD -- as we probably would want to if we adopt ehsan's proposal -- then NS_IMETHODIMP would have no reason to exist.) _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform