Hi John,
On Jul 21, 2009, at 11:09 PM, John McCall wrote:
This patch implements the restrictions on union members detailed in
[class.union]p1, analyzing code like this:
Great!
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(); }
^
Very nice :)
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.
I've committed this with a few minor tweaks, mentioned below. Thanks!
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td (revision 76721)
+++ include/clang/Basic/DiagnosticSemaKinds.td (working copy)
@@ -339,6 +339,18 @@ def err_implicit_object_parameter_init :
"cannot initialize object parameter of type %0 with an expression "
"of type %1">;
+def err_illegal_union_member : Error<
+ "union member %0 has a non-trivial %select{constructor|"
+ "copy constructor|copy assignment operator|destructor}1">;
+def note_nontrivial_has_virtual : Note<
+ "because type %0 has a virtual %select{method|base class}1">;
That should be "member function", not "method", for C++. (We reserve
the term "method" for Objective-C).
/// TranslateIvarVisibility - Translate visibility from a token ID
to an
/// AST enum value.
static ObjCIvarDecl::AccessControl
Index: lib/Sema/Sema.h
===================================================================
--- lib/Sema/Sema.h (revision 76721)
+++ lib/Sema/Sema.h (working copy)
@@ -540,6 +540,14 @@ public:
SourceLocation TSSL,
AccessSpecifier AS, NamedDecl *PrevDecl,
Declarator *D = 0);
+
+ enum cxx_special_member {
+ cxx_default_constructor = 0,
+ cxx_copy_constructor = 1,
+ cxx_copy_assignment = 2,
+ cxx_destructor = 3
+ };
+ void DiagnoseNontrivial(const RecordType* Record,
cxx_special_member mem);
We often use CamelCase for enumerator types and enumerators, so I've
tweaked this to:
enum CXXSpecialMember {
CXXDefaultConstructor = 0,
CXXCopyConstructor = 1,
CXXCopyAssignment = 2,
CXXDestructor = 3
};
Committed as r76766.
- Doug_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits