diff mbox

Some more translation related tweaks

Message ID tkrat.531701baee17c0a8@netcologne.de
State New
Headers show

Commit Message

Volker Reichelt Feb. 27, 2017, 10:04 a.m. UTC
On 26 Feb, Jakub Jelinek wrote:
> On Sun, Feb 26, 2017 at 01:18:57PM +0100, Volker Reichelt wrote:
>> 2017-02-26  Volker Reichelt  <v.reichelt@netcologne.de>
>> 
>> 	* init.c: Include intl.h
> 
> Missing .

Indeed, I noticed that one after I hit the send button.

>> @@ -29,6 +29,7 @@
>>  #include "varasm.h"
>>  #include "gimplify.h"
>>  #include "c-family/c-ubsan.h"
>> +#include "intl.h"
>>  
>>  static bool begin_init_stmts (tree *, tree *);
>>  static tree finish_init_stmts (bool, tree, tree);
>> @@ -2805,11 +2806,11 @@
>>  	{
>>  	  const char *msg;
>>  	  if (typedef_variant_p (orig_type))
>> -	    msg = ("non-constant array new length must be specified "
>> -		   "directly, not by typedef");
>> +	    msg = G_("non-constant array new length must be specified "
>> +		     "directly, not by typedef");
>>  	  else
>> -	    msg = ("non-constant array new length must be specified "
>> -		   "without parentheses around the type-id");
>> +	    msg = G_("non-constant array new length must be specified "
>> +		     "without parentheses around the type-id");
>>  	  pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location),
>>  		   OPT_Wvla, msg);
> 
> This is not -Wformat-security friendly, perhaps better
> 	  pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
> 		   typedef_variant_p (orig_type)
> 		   ? "non-constant array new length must be specified "
> 		     "directly, not by typedef"
> 		   : "non-constant array new length must be specified "
> 		     "without parentheses around the type-id");
> ?

Not quite. Like this the second string doesn't end up in the gcc.pot
file for translation. I had to wrap the second string in G_(...) to make
it work. (I'll have a look for other instances of this pattern and
prepare a separate patch.)

>>  	}
>> Index: gcc/cp/pt.c
>> ===================================================================
>> --- gcc/cp/pt.c	(revision 245719)
>> +++ gcc/cp/pt.c	(working copy)
>> @@ -17190,10 +17190,11 @@
>>  		       stricter.  */
>>  		    bool in_lambda = (current_class_type
>>  				      && LAMBDA_TYPE_P (current_class_type));
>> -		    char const *msg = "%qD was not declared in this scope, "
>> -		      "and no declarations were found by "
>> -		      "argument-dependent lookup at the point "
>> -		      "of instantiation";
>> +		    char const *const msg =
> 
> = should go on the next line in this case, i.e.
> 		      = G_("%qD was not declared in this scope, "

Indeed, thanks for noticing.

> 
> 	Jakub

So here's the second attempt:

2017-02-27  Volker Reichelt  <v.reichelt@netcologne.de>

	* init.c: Include intl.h.
	(build_new_1): Move message strings into pedwarn to make them
	-Wformat-security friendly. Mark string for translation.
	* pt.c (tsubst_copy_and_build): Mark string for translation.
	Make the pointer const.
	* semantics.c (finish_id_expression): Mark strings for translation.

===================================================================

Bootstrapped/regtested on x86_64-linux, ok for trunk?

Regards,
Volker

Comments

Jakub Jelinek Feb. 27, 2017, 10:27 a.m. UTC | #1
On Mon, Feb 27, 2017 at 11:04:36AM +0100, Volker Reichelt wrote:
> > This is not -Wformat-security friendly, perhaps better
> > 	  pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
> > 		   typedef_variant_p (orig_type)
> > 		   ? "non-constant array new length must be specified "
> > 		     "directly, not by typedef"
> > 		   : "non-constant array new length must be specified "
> > 		     "without parentheses around the type-id");
> > ?
> 
> Not quite. Like this the second string doesn't end up in the gcc.pot
> file for translation. I had to wrap the second string in G_(...) to make
> it work. (I'll have a look for other instances of this pattern and
> prepare a separate patch.)

Looks like a xgettext bug or missing feature :(.  Joseph, shall we just
change all those to be G_() around the second string (well, some could be
simplified to be
error_at (loc, "expected %<data%> after %<#pragma acc %s%>", enter ? "enter : "exit");
because the translations should not translate the text in between %< and %>
anyway.

c/c-parser.c-      if (!c_parser_require (parser, CPP_COLON,
c/c-parser.c-                        is_goto
c/c-parser.c:                        ? "expected %<:%>"
c/c-parser.c-                        : "expected %<:%> or %<)%>"))

c/c-parser.c:      error_at (loc, enter
c/c-parser.c-           ? "expected %<data%> after %<#pragma acc enter%>"
c/c-parser.c-           : "expected %<data%> after %<#pragma acc exit%>");

c/c-parser.c-      error_at (loc, enter
c/c-parser.c:           ? "%<#pragma acc enter data%> has no data movement clause"
c/c-parser.c-           : "%<#pragma acc exit data%> has no data movement clause");

cp/call.c-              warning (0, (DECL_CONSTRUCTOR_P (current_function_decl)
cp/call.c:                           ? "pure virtual %q#D called from constructor"
cp/call.c-                           : "pure virtual %q#D called from destructor"),
cp/call.c-                       fn);

cp/decl.c-      inform (DECL_SOURCE_LOCATION (field),
cp/decl.c:              TREE_PRIVATE (field) ? "declared private here"
cp/decl.c-              : "declared protected here");

cp/decl.c-                  error ((flags == DTOR_FLAG)
cp/decl.c:                         ? "destructors may not be ref-qualified"
cp/decl.c-                         : "constructors may not be ref-qualified");

cp/parser.c-      error_at (loc, enter
cp/parser.c:            ? "expected %<data%> after %<#pragma acc enter%>"
cp/parser.c-            : "expected %<data%> after %<#pragma acc exit%>");

coverage.c:       error (is_error < 0 ? "%qs has overflowed" : "%qs is corrupted",
coverage.c-              da_file_name);

omp-offload.c-      error_at (loop->loc,
omp-offload.c-                seq_par
omp-offload.c:                ? "%<seq%> overrides other OpenACC loop specifiers"
omp-offload.c-                : "%<auto%> conflicts with other OpenACC loop "
omp-offload.c-                "specifiers");

Then we have some really non-translatable ones:
c/c-parser.c-      error_at (data->loc,
c/c-parser.c-           "%<#pragma acc routine%> must be applied before %s",
c/c-parser.c:           TREE_USED (fndecl) ? "use" : "definition");
which should be transformed into ? on the whole format string.

	Jakub
Joseph Myers Feb. 27, 2017, 12:47 p.m. UTC | #2
On Mon, 27 Feb 2017, Jakub Jelinek wrote:

> On Mon, Feb 27, 2017 at 11:04:36AM +0100, Volker Reichelt wrote:
> > > This is not -Wformat-security friendly, perhaps better
> > > 	  pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
> > > 		   typedef_variant_p (orig_type)
> > > 		   ? "non-constant array new length must be specified "
> > > 		     "directly, not by typedef"
> > > 		   : "non-constant array new length must be specified "
> > > 		     "without parentheses around the type-id");
> > > ?
> > 
> > Not quite. Like this the second string doesn't end up in the gcc.pot
> > file for translation. I had to wrap the second string in G_(...) to make
> > it work. (I'll have a look for other instances of this pattern and
> > prepare a separate patch.)
> 
> Looks like a xgettext bug or missing feature :(.  Joseph, shall we just
> change all those to be G_() around the second string (well, some could be

Yes, it's generally the case that G_() is used whenever there's a 
conditional expression for the msgid argument to a diagnostic function.
Jakub Jelinek Feb. 27, 2017, 12:49 p.m. UTC | #3
On Mon, Feb 27, 2017 at 11:04:36AM +0100, Volker Reichelt wrote:
> So here's the second attempt:
> 
> 2017-02-27  Volker Reichelt  <v.reichelt@netcologne.de>
> 
> 	* init.c: Include intl.h.
> 	(build_new_1): Move message strings into pedwarn to make them
> 	-Wformat-security friendly. Mark string for translation.
> 	* pt.c (tsubst_copy_and_build): Mark string for translation.
> 	Make the pointer const.
> 	* semantics.c (finish_id_expression): Mark strings for translation.

Ok for trunk then, I'll deal with the rest I've mentioned in another mail
myself.

	Jakub
Volker Reichelt Feb. 27, 2017, 1:33 p.m. UTC | #4
On 27 Feb, Jakub Jelinek wrote:
> On Mon, Feb 27, 2017 at 11:04:36AM +0100, Volker Reichelt wrote:
>> So here's the second attempt:
>> 
>> 2017-02-27  Volker Reichelt  <v.reichelt@netcologne.de>
>> 
>> 	* init.c: Include intl.h.
>> 	(build_new_1): Move message strings into pedwarn to make them
>> 	-Wformat-security friendly. Mark string for translation.
>> 	* pt.c (tsubst_copy_and_build): Mark string for translation.
>> 	Make the pointer const.
>> 	* semantics.c (finish_id_expression): Mark strings for translation.
> 
> Ok for trunk then, I'll deal with the rest I've mentioned in another mail
> myself.
> 
> 	Jakub

Ok, committed as revision 245757.

Volker
diff mbox

Patch

Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 245719)
+++ gcc/cp/init.c	(working copy)
@@ -29,6 +29,7 @@ 
 #include "varasm.h"
 #include "gimplify.h"
 #include "c-family/c-ubsan.h"
+#include "intl.h"
 
 static bool begin_init_stmts (tree *, tree *);
 static tree finish_init_stmts (bool, tree, tree);
@@ -2803,15 +2804,12 @@ 
     {
       if (complain & tf_warning_or_error)
 	{
-	  const char *msg;
-	  if (typedef_variant_p (orig_type))
-	    msg = ("non-constant array new length must be specified "
-		   "directly, not by typedef");
-	  else
-	    msg = ("non-constant array new length must be specified "
-		   "without parentheses around the type-id");
-	  pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location),
-		   OPT_Wvla, msg);
+	  pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
+		   typedef_variant_p (orig_type)
+		   ? "non-constant array new length must be specified "
+		     "directly, not by typedef"
+		   : G_("non-constant array new length must be specified "
+			"without parentheses around the type-id"));
 	}
       else
 	return error_mark_node;
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 245719)
+++ gcc/cp/pt.c	(working copy)
@@ -17190,10 +17190,11 @@ 
 		       stricter.  */
 		    bool in_lambda = (current_class_type
 				      && LAMBDA_TYPE_P (current_class_type));
-		    char const *msg = "%qD was not declared in this scope, "
-		      "and no declarations were found by "
-		      "argument-dependent lookup at the point "
-		      "of instantiation";
+		    char const *const msg
+		      = G_("%qD was not declared in this scope, "
+			   "and no declarations were found by "
+			   "argument-dependent lookup at the point "
+			   "of instantiation");
 
 		    bool diag = true;
 		    if (in_lambda)
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 245719)
+++ gcc/cp/semantics.c	(working copy)
@@ -3510,7 +3510,7 @@ 
 	  && DECL_CONTEXT (decl) == NULL_TREE
 	  && !cp_unevaluated_operand)
 	{
-	  *error_msg = "use of parameter outside function body";
+	  *error_msg = G_("use of parameter outside function body");
 	  return error_mark_node;
 	}
     }
@@ -3520,13 +3520,13 @@ 
   if (TREE_CODE (decl) == TEMPLATE_DECL
       && !DECL_FUNCTION_TEMPLATE_P (decl))
     {
-      *error_msg = "missing template arguments";
+      *error_msg = G_("missing template arguments");
       return error_mark_node;
     }
   else if (TREE_CODE (decl) == TYPE_DECL
 	   || TREE_CODE (decl) == NAMESPACE_DECL)
     {
-      *error_msg = "expected primary-expression";
+      *error_msg = G_("expected primary-expression");
       return error_mark_node;
     }