===================================================================
@@ -11715,13 +11715,22 @@ cp_parser_conversion_type_id (cp_parser* parser)
cp_decl_specifier_seq type_specifiers;
cp_declarator *declarator;
tree type_specified;
+ const char *saved_message;
/* Parse the attributes. */
attributes = cp_parser_attributes_opt (parser);
+
+ saved_message = parser->type_definition_forbidden_message;
+ parser->type_definition_forbidden_message
+ = G_("types may not be defined in a conversion-type-id");
+
/* Parse the type-specifiers. */
cp_parser_type_specifier_seq (parser, /*is_declaration=*/false,
/*is_trailing_return=*/false,
&type_specifiers);
+
+ parser->type_definition_forbidden_message = saved_message;
+
/* If that didn't work, stop. */
if (type_specifiers.type == error_mark_node)
return error_mark_node;
===================================================================
@@ -0,0 +1,6 @@
+// PR c++/57352
+
+struct x
+{
+ operator class {} (); // { dg-error "types|expected" }
+};