From 657184d086a57eb214dda530035563a1ecc3df10 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 11 Apr 2019 17:28:18 +0200 Subject: [PATCH] re PR translation/90035 (Non-translatable C++ parser diagnostics) PR translation/90035 * parser.h (struct cp_parser): Add type_definition_forbidden_message_arg member. * parser.c (cp_debug_parser): Print it. (cp_parser_check_type_definition): Pass parser->type_definition_forbidden_message_arg as second argument to error. (cp_parser_has_attribute_expression, cp_parser_sizeof_operand): Set parser->type_definition_forbidden_message_arg and use G_() with %qs for parser->type_definition_forbidden_message instead of building untranslatable message using concat. From-SVN: r270286 --- gcc/cp/ChangeLog | 14 ++++++++++++++ gcc/cp/parser.c | 41 +++++++++++++++++++++-------------------- gcc/cp/parser.h | 3 +++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9fc4490dc2f..1c0f7446c91 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,17 @@ +2019-04-11 Jakub Jelinek + + PR translation/90035 + * parser.h (struct cp_parser): Add + type_definition_forbidden_message_arg member. + * parser.c (cp_debug_parser): Print it. + (cp_parser_check_type_definition): Pass + parser->type_definition_forbidden_message_arg as second argument to + error. + (cp_parser_has_attribute_expression, cp_parser_sizeof_operand): Set + parser->type_definition_forbidden_message_arg and use G_() with + %qs for parser->type_definition_forbidden_message instead of + building untranslatable message using concat. + 2019-04-09 Jakub Jelinek PR translation/90011 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 348e4acf2d1..3ab371cfa6a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -570,8 +570,10 @@ cp_debug_parser (FILE *file, cp_parser *parser) cp_debug_print_flag (file, "Colon doesn't start a class definition", parser->colon_doesnt_start_class_def_p); if (parser->type_definition_forbidden_message) - fprintf (file, "Error message for forbidden type definitions: %s\n", - parser->type_definition_forbidden_message); + fprintf (file, "Error message for forbidden type definitions: %s %s\n", + parser->type_definition_forbidden_message, + parser->type_definition_forbidden_message_arg + ? parser->type_definition_forbidden_message_arg : ""); cp_debug_print_unparsed_queues (file, parser->unparsed_queues); fprintf (file, "Number of class definitions in progress: %u\n", parser->num_classes_being_defined); @@ -3054,8 +3056,9 @@ cp_parser_check_type_definition (cp_parser* parser) if (parser->type_definition_forbidden_message) { /* Don't use `%s' to print the string, because quotations (`%<', `%>') - in the message need to be interpreted. */ - error (parser->type_definition_forbidden_message); + or %qs in the message need to be interpreted. */ + error (parser->type_definition_forbidden_message, + parser->type_definition_forbidden_message_arg); return false; } return true; @@ -8518,12 +8521,12 @@ cp_parser_has_attribute_expression (cp_parser *parser) /* Types cannot be defined in a `sizeof' expression. Save away the old message. */ const char *saved_message = parser->type_definition_forbidden_message; - /* And create the new one. */ - const int kwd = RID_BUILTIN_HAS_ATTRIBUTE; - char *tmp = concat ("types may not be defined in %<", - IDENTIFIER_POINTER (ridpointers[kwd]), - "%> expressions", NULL); - parser->type_definition_forbidden_message = tmp; + const char *saved_message_arg + = parser->type_definition_forbidden_message_arg; + parser->type_definition_forbidden_message + = G_("types may not be defined in %qs expressions"); + parser->type_definition_forbidden_message_arg + = IDENTIFIER_POINTER (ridpointers[RID_BUILTIN_HAS_ATTRIBUTE]); /* The restrictions on constant-expressions do not apply inside sizeof expressions. */ @@ -8562,10 +8565,9 @@ cp_parser_has_attribute_expression (cp_parser *parser) --cp_unevaluated_operand; --c_inhibit_evaluation_warnings; - /* Free the message we created. */ - free (tmp); /* And restore the old one. */ parser->type_definition_forbidden_message = saved_message; + parser->type_definition_forbidden_message_arg = saved_message_arg; parser->integral_constant_expression_p = saved_integral_constant_expression_p; parser->non_integral_constant_expression_p @@ -28928,7 +28930,7 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword) { tree expr = NULL_TREE; const char *saved_message; - char *tmp; + const char *saved_message_arg; bool saved_integral_constant_expression_p; bool saved_non_integral_constant_expression_p; @@ -28941,11 +28943,11 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword) /* Types cannot be defined in a `sizeof' expression. Save away the old message. */ saved_message = parser->type_definition_forbidden_message; - /* And create the new one. */ - tmp = concat ("types may not be defined in %<", - IDENTIFIER_POINTER (ridpointers[keyword]), - "%> expressions", NULL); - parser->type_definition_forbidden_message = tmp; + saved_message_arg = parser->type_definition_forbidden_message_arg; + parser->type_definition_forbidden_message + = G_("types may not be defined in %qs expressions"); + parser->type_definition_forbidden_message_arg + = IDENTIFIER_POINTER (ridpointers[keyword]); /* The restrictions on constant-expressions do not apply inside sizeof expressions. */ @@ -29002,10 +29004,9 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword) --cp_unevaluated_operand; --c_inhibit_evaluation_warnings; - /* Free the message we created. */ - free (tmp); /* And restore the old one. */ parser->type_definition_forbidden_message = saved_message; + parser->type_definition_forbidden_message_arg = saved_message_arg; parser->integral_constant_expression_p = saved_integral_constant_expression_p; parser->non_integral_constant_expression_p diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h index 1d6cb2d424c..c03a9d87af5 100644 --- a/gcc/cp/parser.h +++ b/gcc/cp/parser.h @@ -350,6 +350,9 @@ struct GTY(()) cp_parser { issued as an error message if a type is defined. */ const char *type_definition_forbidden_message; + /* Argument for type_definition_forbidden_message if needed. */ + const char *type_definition_forbidden_message_arg; + /* A stack used for member functions of local classes. The lists contained in an individual entry can only be processed once the outermost class being defined is complete. */ -- 2.30.2