/* When parsing of the noexcept-specifier should be delayed. */
CP_PARSER_FLAGS_DELAY_NOEXCEPT = 0x40,
/* When parsing a consteval declarator. */
- CP_PARSER_FLAGS_CONSTEVAL = 0x80
+ CP_PARSER_FLAGS_CONSTEVAL = 0x80,
+ /* When parsing a parameter declaration. */
+ CP_PARSER_FLAGS_PARAMETER = 0x100
};
/* This type is used for parameters and variables which hold
/* Special case for "this" specifier, indicating a parm is an xobj parm.
The "this" specifier must be the first specifier in the declaration,
after any attributes. */
- if (token->keyword == RID_THIS)
+ if (token->keyword == RID_THIS && (flags & CP_PARSER_FLAGS_PARAMETER))
{
cp_lexer_consume_token (parser->lexer);
if (token != first_specifier)
/* Parse the declaration-specifiers. */
cp_token *decl_spec_token_start = cp_lexer_peek_token (parser->lexer);
cp_parser_decl_specifier_seq (parser,
- flags,
+ flags | CP_PARSER_FLAGS_PARAMETER,
&decl_specifiers,
&declares_class_or_enum);
--- /dev/null
+// PR c++/113788
+// { dg-do compile { target c++11 } }
+
+struct S { int a, b; };
+struct U {
+ void foo () { this int g = 1; } // { dg-error "expected ';' before 'int'" }
+};
+this auto h = 1; // { dg-error "expected unqualified-id before 'this'" }
+
+int
+main ()
+{
+ S s = { 1, 2 };
+ short t[3] = { 3, 4, 5 };
+ this auto &[a, b] = s; // { dg-error "invalid use of 'this' in non-member function" }
+ this auto &[c, d, e] = t; // { dg-error "invalid use of 'this' in non-member function" }
+ this int f = 1; // { dg-error "invalid use of 'this' in non-member function" }
+ for (this auto &i : t) // { dg-error "invalid use of 'this' in non-member function" }
+ ; // { dg-error "expected" }
+} // { dg-error "expected" }