re PR translation/90035 (Non-translatable C++ parser diagnostics)
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Apr 2019 15:28:18 +0000 (17:28 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Apr 2019 15:28:18 +0000 (17:28 +0200)
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
gcc/cp/parser.c
gcc/cp/parser.h

index 9fc4490dc2f94b4bf4fa164bc926aa24167b3c8b..1c0f7446c91f264390e958a03f4034e90a84b361 100644 (file)
@@ -1,3 +1,17 @@
+2019-04-11  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <jakub@redhat.com>
 
        PR translation/90011
index 348e4acf2d10356f31c0e9940c063778d0acaad0..3ab371cfa6a814097aa8cb8da7eaa2b391f363d9 100644 (file)
@@ -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 : "<none>");
   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
index 1d6cb2d424c8eb1819844e31dfa5b47058d03676..c03a9d87af591c91b3b289e614605faf5f7c5673 100644 (file)
@@ -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.  */