From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17347 invoked by alias); 27 Feb 2017 10:04:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 17057 invoked by uid 89); 27 Feb 2017 10:04:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.8 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPAM_BODY,SPF_PASS autolearn=ham version=3.3.2 spammy=noticing X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Feb 2017 10:04:42 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 639AC13321; Mon, 27 Feb 2017 11:04:39 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 546A911DA8; Mon, 27 Feb 2017 11:04:39 +0100 (CET) Received: from [89.0.2.235] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 58b3f9b7-0242-7f0000012729-7f000001bf8a-1 for ; Mon, 27 Feb 2017 11:04:39 +0100 Received: from linux-w03z.fritz.box (xdsl-89-0-2-235.netcologne.de [89.0.2.235]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA; Mon, 27 Feb 2017 11:04:36 +0100 (CET) Date: Mon, 27 Feb 2017 10:27:00 -0000 From: Volker Reichelt Subject: Re: [PATCH] Some more translation related tweaks To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org, Marek Polacek In-Reply-To: <20170226123555.GW1849@tucnak> Message-ID: References: <20170226123555.GW1849@tucnak> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=us-ascii Content-Disposition: INLINE X-SW-Source: 2017-02/txt/msg01596.txt.bz2 On 26 Feb, Jakub Jelinek wrote: > On Sun, Feb 26, 2017 at 01:18:57PM +0100, Volker Reichelt wrote: >> 2017-02-26 Volker Reichelt >> >> * 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 * 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. 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; } =================================================================== Bootstrapped/regtested on x86_64-linux, ok for trunk? Regards, Volker