[pushed] c++: use G_ instead of _

Message ID 20231019153158.1937301-1-jason@redhat.com
State Accepted
Headers
Series [pushed] c++: use G_ instead of _ |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Jason Merrill Oct. 19, 2023, 3:31 p.m. UTC
  Tested with make po/gcc.pot to see that the strings are still there (though in
a different place, now with the gcc-internal-format tag).

Applying to trunk.

-- 8< --

Since these strings are passed to error_at, they should be marked for
translation with G_, like other diagnostic messages, rather than _, which
forces immediate (redundant) translation.  The use of N_ is less
problematic, but also imprecise.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_primary_expression): Use G_.
	(cp_parser_using_enum): Likewise.
	* decl.cc (identify_goto): Likewise.
---
 gcc/cp/decl.cc   |  4 ++--
 gcc/cp/parser.cc | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)


base-commit: 04d6c74564b7eb51660a00b35353aeab706b5a50
  

Comments

Jakub Jelinek Oct. 19, 2023, 3:42 p.m. UTC | #1
On Thu, Oct 19, 2023 at 11:31:58AM -0400, Jason Merrill wrote:
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -3607,8 +3607,8 @@ identify_goto (tree decl, location_t loc, const location_t *locus,
>  {
>    bool complained
>      = emit_diagnostic (diag_kind, loc, 0,
> -		       decl ? N_("jump to label %qD")
> -		       : N_("jump to case label"), decl);
> +		       decl ? G_("jump to label %qD")

N_ for this is wrong because gettext will then not properly verify
translators didn't screw things up by using some incompatible format
string in the translation.
I believe some translations e.g. changed %s to %S.  And that seems to be
still the case:
grep -B3 '[^%]%S' po/*.po
po/sr.po-#, fuzzy, gcc-internal-format
po/sr.po-#| msgid "Duplicate %s attribute specified at %L"
po/sr.po-msgid "Multiple %qs modifiers specified at %C"
po/sr.po:msgstr "Удвостручени атрибут %S наведен код %L"
--
po/sr.po-#, fuzzy, gcc-internal-format, gfc-internal-format
po/sr.po-#| msgid "Duplicate %s attribute specified at %L"
po/sr.po-msgid "Duplicate %s attribute specified at %L"
po/sr.po:msgstr "Удвостручени атрибут %S наведен код %L"
--
po/sr.po-#, fuzzy, gcc-internal-format, gfc-internal-format
po/sr.po-#| msgid "Duplicate %s attribute specified at %L"
po/sr.po-msgid "Duplicate BIND attribute specified at %L"
po/sr.po:msgstr "Удвостручени атрибут %S наведен код %L"
--
po/tr.po-#, fuzzy, gcc-internal-format, gfc-internal-format
po/tr.po-#| msgid "%s statement must appear in a MODULE"
po/tr.po-msgid "%s statement must appear in a MODULE"
po/tr.po:msgstr "%S deyimi bir MODULE'de görünmemeli"

> +		       : G_("jump to case label"), decl);

While in this case G_ is better just for consistency, N_ would work
exactly the same given that there are no format strings.

	Jakub
  

Patch

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 255c4026bdb..ce4c89dea70 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -3607,8 +3607,8 @@  identify_goto (tree decl, location_t loc, const location_t *locus,
 {
   bool complained
     = emit_diagnostic (diag_kind, loc, 0,
-		       decl ? N_("jump to label %qD")
-		       : N_("jump to case label"), decl);
+		       decl ? G_("jump to label %qD")
+		       : G_("jump to case label"), decl);
   if (complained && locus)
     inform (*locus, "  from here");
   return complained;
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 57b62fb7363..c77e93ef104 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -6206,8 +6206,8 @@  cp_parser_primary_expression (cp_parser *parser,
 	      {
 		const char *msg
 		  = (TREE_CODE (decl) == PARM_DECL
-		     ? _("parameter %qD may not appear in this context")
-		     : _("local variable %qD may not appear in this context"));
+		     ? G_("parameter %qD may not appear in this context")
+		     : G_("local variable %qD may not appear in this context"));
 		error_at (id_expression.get_location (), msg,
 			  decl.get_value ());
 		return error_mark_node;
@@ -22145,16 +22145,16 @@  cp_parser_using_enum (cp_parser *parser)
      shall have a reachable enum-specifier.  */
   const char *msg = nullptr;
   if (cxx_dialect < cxx20)
-    msg = _("%<using enum%> "
-	    "only available with %<-std=c++20%> or %<-std=gnu++20%>");
+    msg = G_("%<using enum%> "
+	     "only available with %<-std=c++20%> or %<-std=gnu++20%>");
   else if (dependent_type_p (type))
-    msg = _("%<using enum%> of dependent type %qT");
+    msg = G_("%<using enum%> of dependent type %qT");
   else if (TREE_CODE (type) != ENUMERAL_TYPE)
-    msg = _("%<using enum%> of non-enumeration type %q#T");
+    msg = G_("%<using enum%> of non-enumeration type %q#T");
   else if (!COMPLETE_TYPE_P (type))
-    msg = _("%<using enum%> of incomplete type %qT");
+    msg = G_("%<using enum%> of incomplete type %qT");
   else if (OPAQUE_ENUM_P (type))
-    msg = _("%<using enum%> of %qT before its enum-specifier");
+    msg = G_("%<using enum%> of %qT before its enum-specifier");
   if (msg)
     {
       location_t loc = make_location (start, start, end);