[cfe-commits] PR12204 PATCH: static_cast to Base class overrides the Derived class field.

Richard Smith richard at metafoo.co.uk
Wed Mar 28 11:50:08 PDT 2012


On Wed, Mar 28, 2012 at 11:33 AM, Stepan Dyatkovskiy <stpworld at narod.ru>wrote:

> Hello John.
> I attached reworked patch.
> I couldn't found in CXXRecordDecl methods like "isFinal", but I know only
> 2 ways to make class final in C++:
>
> 1. Make dtor private (will work only with dynamic allocation):
>
> class Final {
> ~Final() {}
> public:
>  Final* create() { return new Final(); }
> };
>
> 2. Make dtor and ctor private, and create friend-child using virtual
> inharitance:
>
> class Finalizer {
> Final() {}
> ~Final() {}
> friend class Final;
> };
>
> class Final : virtual public Finalizer {
> };
>
> As I found, second way in clang doesn't use EmitAggregateCopy for
> assignment "Final = Final", so I wrote the check for first case only.
>

In case 1, Final can still be derived from in friends and members of the
class. In case 2, it can still be derived from in friends and members of
Finalizer, and in members of Final. John is referring to the C++11 'final'
feature:

class Final final {
};

You can check for this with Record->hasAttr<FinalAttr>().

- Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120328/86bfbcba/attachment.html>


More information about the cfe-commits mailing list