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

Stepan Dyatkovskiy stpworld at narod.ru
Wed Mar 28 11:33:13 PDT 2012


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.

P.S.:
Anyway I have implemented check for second case. I just excluded it from 
current patch.

-Stepan.

John McCall wrote:
> I think this patch is the wrong approach.  Instead, EmitAggregateCopy should be modified so that it always copies structs using their data size if either the source or the destination might be a base-class subobject.  There is no need to adjust the alignment.
>
> We should conservatively assume that an object might be a base-class subobject if this is C++ and the class is not marked final.  This is probably going to hurt the performance of generated code in some cases, and we should add a flag indicating that both objects are known to not be base-class subobjects.  This flag should default to false.
>
> If you wouldn't mind writing up a new patch based on this approach, I'll save the code-style comments for that.
>
> John.
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr12204-2.1.patch
Type: text/x-patch
Size: 4266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120328/69a844d6/attachment.bin>


More information about the cfe-commits mailing list