<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi John,<div><br><div><div>On Jul 21, 2009, at 11:09 PM, John McCall wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>This patch implements the restrictions on union members detailed in [class.union]p1, analyzing code like this:<br></div></blockquote><div><br></div>Great!</div><div><br><blockquote type="cite"><div>class Dtor {<br>~Dtor() { abort(); }<br>};<br>union U3 {<br>struct s6 : Dtor {<br>} m6;<br>};<br><br>to produce errors like this:<br><br>test/CXX/class/class.union/p1.cpp:79:5: error: union member 'm6' has a non-trivial destructor<br>} m6;<br>^<br>test/CXX/class/class.union/p1.cpp:78:15: note: because type 'struct U3::s6' has a base class with a non-trivial destructor<br>struct s6 : Dtor {<br>^<br>test/CXX/class/class.union/p1.cpp:30:3: note: because type 'class Dtor' has a user-declared destructor<br>~Dtor() { abort(); }<br>^<br></div></blockquote><div><br></div>Very nice :)</div><div><br></div><div><blockquote type="cite"><div>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.<br></div></blockquote><div><br></div><div><br></div>I've committed this with a few minor tweaks, mentioned below. Thanks!</div><div><br><blockquote type="cite"><div><br>Index: include/clang/Basic/DiagnosticSemaKinds.td<br>===================================================================<br>--- include/clang/Basic/DiagnosticSemaKinds.td<span class="Apple-tab-span" style="white-space:pre">        </span>(revision 76721)<br>+++ include/clang/Basic/DiagnosticSemaKinds.td<span class="Apple-tab-span" style="white-space:pre">    </span>(working copy)<br>@@ -339,6 +339,18 @@ def err_implicit_object_parameter_init :<br>   "cannot initialize object parameter of type %0 with an expression "<br>   "of type %1">;<br><br>+def err_illegal_union_member : Error<<br>+  "union member %0 has a non-trivial %select{constructor|"<br>+  "copy constructor|copy assignment operator|destructor}1">;<br>+def note_nontrivial_has_virtual : Note<<br>+  "because type %0 has a virtual %select{method|base class}1">;<br></div></blockquote><div><br></div>That should be "member function", not "method", for C++. (We reserve the term "method" for Objective-C).</div><div><br></div><div><blockquote type="cite"><div> /// TranslateIvarVisibility - Translate visibility from a token ID to an <br> ///  AST enum value.<br> static ObjCIvarDecl::AccessControl<br>Index: lib/Sema/Sema.h<br>===================================================================<br>--- lib/Sema/Sema.h<span class="Apple-tab-span" style="white-space:pre">      </span>(revision 76721)<br>+++ lib/Sema/Sema.h<span class="Apple-tab-span" style="white-space:pre">       </span>(working copy)<br>@@ -540,6 +540,14 @@ public:<br>                             SourceLocation TSSL,<br>                             AccessSpecifier AS, NamedDecl *PrevDecl,<br>                             Declarator *D = 0);<br>+<br>+  enum cxx_special_member {<br>+    cxx_default_constructor = 0,<br>+    cxx_copy_constructor = 1,<br>+    cxx_copy_assignment = 2,<br>+    cxx_destructor = 3<br>+  };<br>+  void DiagnoseNontrivial(const RecordType* Record, cxx_special_member mem);<br></div></blockquote><div><br></div><div>We often use CamelCase for enumerator types and enumerators, so I've tweaked this to:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(50, 89, 93); "><span style="color: #000000">  </span><span style="color: #ba27a1">enum</span><span style="color: #000000"> </span>CXXSpecialMember<span style="color: #000000"> {</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(50, 89, 93); "><span style="color: #000000">    </span>CXXDefaultConstructor<span style="color: #000000"> = </span><span style="color: #271cd7">0</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(50, 89, 93); "><span style="color: #000000">    </span>CXXCopyConstructor<span style="color: #000000"> = </span><span style="color: #271cd7">1</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(50, 89, 93); "><span style="color: #000000">    </span>CXXCopyAssignment<span style="color: #000000"> = </span><span style="color: #271cd7">2</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(50, 89, 93); "><span style="color: #000000">    </span>CXXDestructor<span style="color: #000000"> = </span><span style="color: #271cd7">3</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">  };</div><div><font class="Apple-style-span" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px;">Committed as r76766.</span></font></div><div><font class="Apple-style-span" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div></div></div><span class="Apple-tab-span" style="white-space:pre">       </span>- Doug</div></body></html>