On Mon, Oct 1, 2012 at 3:56 PM, Michael Han <span dir="ltr"><<a href="mailto:Michael.Han@autodesk.com" target="_blank">Michael.Han@autodesk.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Attached patch is trying to improve the C++ 11 generalized attributes support in Clang:<br>
<br>
- Parse generic C++ 11 attributes into AST instead of parsing and ignoring them.<br>
- Parse attributes arguments if the attributes are in gnu scope.<br>
- Update several tests since with the unknown attributes introduced to AST some expected diagnostics shall be emitted.<br>
<br>
This would allow one to extend Clang attributes using C++ 11 attribute syntax and migrate existing GNU style attributes with new syntax.<br></blockquote><div><br></div><div>We had been deliberately holding back on that, waiting for the GCC guys to commit to a particular approach. It looks like they're just putting all their existing attributes into a gnu:: namespace, though, so this is fine:</div>
<div><br></div><div><a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53528">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53528</a></div><div><a href="http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01348.html">http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01348.html</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Are there any ideas and plans on adding generalized C++ 11 attribute support to Clang? I feel migrating existing GNU attributes to new syntax might be a good start. Any feedback are appreciated.</blockquote><div><br></div>
<div>C++11 attributes certainly need more love, and such work would be very much appreciated. In terms of the standard C++11 pieces, we have a few deficiencies: We don't accept attributes (and alignas) in quite the right set of places, nor do we apply them to the right set of entities, we get the semantics of [[noreturn]] wrong (we use the GNU __attribute__((noreturn)) semantics, which don't quite match), and we don't issue an error for an attribute which is applied to an entity to which it can't appertain.</div>
<div><br></div><div>On to your patch:</div><div><br></div><div>+++ lib/Parse/ParseDeclCXX.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div><div><div>@@ -2963,46 +2963,35 @@</div></div><div>
<div>+ if (ScopeName && ScopeName->getName() == "gnu") {</div><div>+ ParseCXX11AttributeGNUStyleArgs(AttrName, AttrLoc, ScopeName,</div><div>+ ScopeLoc, attrs);</div>
</div><div><br></div><div>Please add some tests for this.</div><div><br></div><div><div>+ // FIXME: handle other formats of c++11 attribute arguments</div></div><div><div>+ ConsumeParen();</div><div>+ SkipUntil(tok::r_paren, false);</div>
</div><div><br></div><div>It looks like this silently drops unknown attributes followed by parens. Can we add them to the list in this case, so we'll get a warning?</div><div><br></div><div>[...]</div><div><div>+ if (StandardAttr)</div>
<div> Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)</div><div> << AttrName->getName();</div><div><br></div></div><div>Please reject ellipses for GNU attributes too, for now (with an 'unsupported' error), rather than silently dropping them.</div>
<div><br></div><div><div>@@ -3014,6 +3003,75 @@</div><div> SkipUntil(tok::r_square, false);</div><div> }</div><div> </div><div>+bool Parser::IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName,</div><div>+ IdentifierInfo *ScopeName) {</div>
</div><div><br></div><div>Make this a static, non-member function.</div><div><br></div><div><div>+void Parser::ParseCXX11AttributeGNUStyleArgs(IdentifierInfo *AttrName,</div><div>+ SourceLocation AttrNameLoc,</div>
<div>+ IdentifierInfo *ScopeName,</div><div>+ SourceLocation ScopeLoc,</div><div>+ ParsedAttributes &Attrs) {</div>
</div><div><br></div><div>Can you share this code between C++11 and GNU attribute parsing?</div><div><br></div><div><div>+++ test/Parser/cxx11-stmt-attributes.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div>
<div>@@ -2,53 +2,55 @@</div><div> </div><div> void foo(int i) {</div><div>+ [[unknown_attribute]] ; // expected-warning {{attribute unknown_attribute cannot be specified on a statement}}</div></div><div><br></div><div>Yuck. Would you be interested in teaching this warning the difference between 'attribute cannot be specified on a statement' and 'unknown attribute'?</div>
</div>