mardi 22 juin 2021

Misleading description concerning the 'final' Keyword in the C++11 standard?

class A
{
    virtual void foo();
}

class B : public A
{
    void foo() final;
}

Quote from C++11 standard § 9.2/8:

A virt-specifier-seq shall contain at most one of each virt-specifier. A virt-specifier-seq shall appear only in the declaration of a virtual member function (10.3)

A virt-specifier includes final and override.

Function foo in class B is a derived virtual member function (even not declared as virtual in B). This is legal according to the above quote from the C++11 standard.

But what is with the following case:

class C
{
    virtual void bar() final;
}

According to the C++11 standard class C should compile, though the virtual and final keywords are contrary.

Therefore the C++11 standard $9.2/8 confused me a little bit. It's not precise enough. I don't even know if this really compiles, and if its behaviour is well defined.

Aucun commentaire:

Enregistrer un commentaire