[PATCH] GNU-style attributes and lambdas

Richard Smith richard at metafoo.co.uk
Tue Mar 11 16:27:46 PDT 2014


@@ -1083,7 +1086,12 @@
       << FixItHint::CreateInsertion(Tok.getLocation(), "() ");
     SourceLocation DeclLoc = Tok.getLocation();
     SourceLocation DeclEndLoc = DeclLoc;
-
+
+    // GNU-style attributes must be parsed before the mutable specifier to
be
+    // compatible with GCC.
+    ParsedAttributes Attr(AttrFactory);
+    MaybeParseGNUAttributes(Attr, &DeclEndLoc);


We can't have GNU attributes here: we're inside an "if
(Tok.is(tok::kw_mutable) || Tok.is(tok::arrow))" and we've not parsed any
tokens yet. GCC doesn't accept

  [] __attribute__(( )) {}

... so I don't think we need to deal with __attribute__ with missing
preceding parens (but it might be nice to do so anyway, if you want!).

Patch looks good with that change reverted.


On Tue, Mar 11, 2014 at 4:19 PM, Aaron Ballman <aaron at aaronballman.com>wrote:

> GCC allows GNU-style attributes to be applied to a lambda expression,
> and such attributes can appertain to the underlying declarations
> instead of the types. For instance:
>
> void f2() {
>   [](const char *, ...) __attribute__((sentinel)) { }("%s", 1);
> }
>
> In GCC, these attributes must appear before the mutable or exception
> specifier for the lambda (instead of after, like with C++11-style
> attributes), and this patch is implemented to match that expectation.
>
> ~Aaron
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140311/458fe6f3/attachment.html>


More information about the cfe-commits mailing list