[gcc r9-9254] c++: Allow GNU attributes before lambda -> [PR90333]

Jason Merrill jason@gcc.gnu.org
Sat Feb 27 20:43:23 GMT 2021


https://gcc.gnu.org/g:74d34ca781cf94c8b4979c524dbbfbe95863678a

commit r9-9254-g74d34ca781cf94c8b4979c524dbbfbe95863678a
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 26 05:45:02 2021 -0500

    c++: Allow GNU attributes before lambda -> [PR90333]
    
    In my 9.3/10 patch for 90333 I allowed attributes between [] and (), and
    after the trailing return type, but not in the place that GCC 8 expected
    them, and we've gotten several bug reports about that.  So let's allow them
    there, as well.
    
    gcc/cp/ChangeLog:
    
            PR c++/90333
            * parser.c (cp_parser_lambda_declarator_opt): Accept GNU attributes
            between () and ->.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/90333
            * g++.dg/ext/attr-lambda3.C: New test.

Diff:
---
 gcc/cp/parser.c                         | 11 +++++++++--
 gcc/testsuite/g++.dg/ext/attr-lambda3.C |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d6fb5749d9d..1582f2a6155 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10907,7 +10907,12 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
       /* Parse optional exception specification.  */
       exception_spec = cp_parser_exception_specification_opt (parser);
 
-      std_attrs = cp_parser_std_attribute_spec_seq (parser);
+      /* GCC 8 accepted attributes here, and this is the place for standard
+	 C++11 attributes that appertain to the function type.  */
+      if (cp_next_tokens_can_be_gnu_attribute_p (parser))
+	gnu_attrs = cp_parser_gnu_attributes_opt (parser);
+      else
+	std_attrs = cp_parser_std_attribute_spec_seq (parser);
 
       /* Parse optional trailing return type.  */
       if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF))
@@ -10916,8 +10921,10 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
           return_type = cp_parser_trailing_type_id (parser);
         }
 
+      /* Also allow GNU attributes at the very end of the declaration, the
+	 usual place for GNU attributes.  */
       if (cp_next_tokens_can_be_gnu_attribute_p (parser))
-	gnu_attrs = cp_parser_gnu_attributes_opt (parser);
+	gnu_attrs = chainon (gnu_attrs, cp_parser_gnu_attributes_opt (parser));
 
       /* The function parameters must be in scope all the way until after the
          trailing-return-type in case of decltype.  */
diff --git a/gcc/testsuite/g++.dg/ext/attr-lambda3.C b/gcc/testsuite/g++.dg/ext/attr-lambda3.C
new file mode 100644
index 00000000000..f9c3ec11fe9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-lambda3.C
@@ -0,0 +1,4 @@
+// PR c++/90333
+// { dg-do compile { target c++11 } }
+
+auto x = []() __attribute__((always_inline)) -> int { return 0; }


More information about the Gcc-cvs mailing list