On Fri, May 02, 2014 at 05:01:18PM +0000, Joseph S. Myers wrote: > On Tue, 29 Apr 2014, Marek Polacek wrote: > > > It's correct to warn about returning an address of a local label, > > but it's clumsy to say it's "local variable. We can easily distinguish > > between a label and a variable. > > > > Regtested/bootstrapped on x86_64-linux, ok for trunk? > > You always need to have complete sentences in diagnostics for the sake of > translation. Thus, you need two separate warning_at calls, one with each > version of the message. (Using ? : for the whole format string isn't > sufficient; I think xgettext only extracts one of the two alternatives for > translation if you do that.)
Ooops. Is it ok to fix it up with this patch then? 2014-05-02 Marek Polacek <pola...@redhat.com> c/ * c-typeck.c (c_finish_return): Separate warning_at calls. cp/ * typeck.c (maybe_warn_about_returning_address_of_local): Separate warning_at calls. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index b95fd89..f7ad91e 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -9273,10 +9273,14 @@ c_finish_return (location_t loc, tree retval, tree origtype) && !DECL_EXTERNAL (inner) && !TREE_STATIC (inner) && DECL_CONTEXT (inner) == current_function_decl) - warning_at (loc, - OPT_Wreturn_local_addr, "function returns address " - "of %s", TREE_CODE (inner) == LABEL_DECL - ? "label" : "local variable"); + { + if (TREE_CODE (inner) == LABEL_DECL) + warning_at (loc, OPT_Wreturn_local_addr, + "function returns address of label"); + else + warning_at (loc, OPT_Wreturn_local_addr, + "function returns address of local variable"); + } break; default: diff --git gcc/cp/typeck.c gcc/cp/typeck.c index 8b7cb8d..7b28a9a 100644 --- gcc/cp/typeck.c +++ gcc/cp/typeck.c @@ -8309,10 +8309,12 @@ maybe_warn_about_returning_address_of_local (tree retval) if (TREE_CODE (valtype) == REFERENCE_TYPE) warning (OPT_Wreturn_local_addr, "reference to local variable %q+D returned", whats_returned); + else if (TREE_CODE (whats_returned) == LABEL_DECL) + warning (OPT_Wreturn_local_addr, "address of label %q+D returned", + whats_returned); else - warning (OPT_Wreturn_local_addr, "address of %s %q+D returned", - TREE_CODE (whats_returned) == LABEL_DECL - ? "label" : "local variable", whats_returned); + warning (OPT_Wreturn_local_addr, "address of local variable %q+D " + "returned", whats_returned); return; } } Marek