+2020-01-29 Jason Merrill <jason@redhat.com>
+
+ PR c++/90333
+ PR c++/89640
+ PR c++/60503
+ * parser.c (cp_parser_type_specifier_seq): Don't parse attributes in
+ a trailing return type.
+ (cp_parser_lambda_declarator_opt): Parse C++11 attributes before
+ parens.
+
2020-01-29 Marek Polacek <polacek@redhat.com>
PR c++/91754 - Fix template arguments comparison with class NTTP.
++parser->num_template_parameter_lists;
}
+ /* Committee discussion supports allowing attributes here. */
+ lambda_specs.attributes = cp_parser_attributes_opt (parser);
+
/* The parameter-declaration-clause is optional (unless
template-parameter-list was given), but must begin with an
opening parenthesis if present. */
fco = grokmethod (&return_type_specs,
declarator,
- gnu_attrs);
+ chainon (gnu_attrs, lambda_specs.attributes));
if (fco != error_mark_node)
{
DECL_INITIALIZED_IN_CLASS_P (fco) = 1;
/* Check for attributes first. */
if (cp_next_tokens_can_be_attribute_p (parser))
{
+ /* GNU attributes at the end of a declaration apply to the
+ declaration as a whole, not to the trailing return type. So look
+ ahead to see if these attributes are at the end. */
+ if (seen_type_specifier && is_trailing_return
+ && cp_next_tokens_can_be_gnu_attribute_p (parser))
+ {
+ size_t n = cp_parser_skip_attributes_opt (parser, 1);
+ cp_token *tok = cp_lexer_peek_nth_token (parser->lexer, n);
+ if (tok->type == CPP_SEMICOLON || tok->type == CPP_COMMA
+ || tok->type == CPP_EQ || tok->type == CPP_OPEN_BRACE)
+ break;
+ }
type_specifier_seq->attributes
= attr_chainon (type_specifier_seq->attributes,
cp_parser_attributes_opt (parser));
--- /dev/null
+// PR c++/90333
+// { dg-do compile { target c++11 } }
+
+auto l = [] [[nodiscard]] () -> int { return 0; };
+auto l2 = []() -> int __attribute ((warn_unused_result)) { return 0; };
+auto f() -> int __attribute ((warn_unused_result));
+auto f() -> int { return 0; }
+
+int main()
+{
+ l(); // { dg-warning "nodiscard" }
+ l2(); // { dg-warning "unused_result" }
+ f(); // { dg-warning "unused_result" }
+}