[cfe-commits] [patch] semantic analysis for union members in C++

John McCall rjmccall at apple.com
Tue Jul 21 23:09:13 PDT 2009

This patch implements the restrictions on union members detailed in 
[class.union]p1, analyzing code like this:

class Dtor {
~Dtor() { abort(); }
union U3 {
struct s6 : Dtor {
} m6;

to produce errors like this:

test/CXX/class/class.union/p1.cpp:79:5: error: union member 'm6' has a 
non-trivial destructor
} m6;
test/CXX/class/class.union/p1.cpp:78:15: note: because type 'struct 
U3::s6' has a base class with a non-trivial destructor
struct s6 : Dtor {
test/CXX/class/class.union/p1.cpp:30:3: note: because type 'class Dtor' 
has a user-declared destructor
~Dtor() { abort(); }

This resolves bug #3404, as well as paving the way for implementing type 
traits based on having trivial copy constructors &c. which we'll be 
wanting shortly.

I went ahead and implemented a few bits of convenient API — in 
particular, CXXRecordDecl::method_iterator and ::ctor_iterator — and 
fixed a few mildly-related bugs, including a very small memory leak 
which happened on every derivation from a virtual base class. If people 
want me to tease these out into a separate patch, that's not a problem.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090721/eb1a628d/attachment.txt>

More information about the cfe-commits mailing list