public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5314] c++: Quash bogus -Wunused-value with new [PR107797] Date: Mon, 23 Jan 2023 21:42:25 +0000 (GMT) [thread overview] Message-ID: <20230123214225.A98283858D33@sourceware.org> (raw) https://gcc.gnu.org/g:e3585e6acdfd5c1793f877476647d2521620c95c commit r13-5314-ge3585e6acdfd5c1793f877476647d2521620c95c Author: Marek Polacek <polacek@redhat.com> Date: Thu Jan 19 17:12:34 2023 -0500 c++: Quash bogus -Wunused-value with new [PR107797] We shouldn't emit "right operand of comma operator has no effect" when that comma operator was created by the compiler for "new int{}". convert_to_void/COMPOUND_EXPR already checks warning_suppressed_p so we can just suppress -Wunused-value. PR c++/107797 gcc/cp/ChangeLog: * cvt.cc (ocp_convert): copy_warning when creating a new COMPOUND_EXPR. * init.cc (build_new_1): Suppress -Wunused-value on compiler-generated COMPOUND_EXPRs. gcc/testsuite/ChangeLog: * g++.dg/warn/Wunused-value-1.C: New test. Diff: --- gcc/cp/cvt.cc | 6 ++++-- gcc/cp/init.cc | 2 ++ gcc/testsuite/g++.dg/warn/Wunused-value-1.C | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index 0cbfd8060cb..17827d06a4a 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -711,8 +711,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags, return error_mark_node; if (e == TREE_OPERAND (expr, 1)) return expr; - return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e), - TREE_OPERAND (expr, 0), e); + e = build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e), + TREE_OPERAND (expr, 0), e); + copy_warning (e, expr); + return e; } complete_type (type); diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index f816c474cef..52e96fbe590 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -3800,6 +3800,8 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, if (cookie_expr) rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval); + suppress_warning (rval, OPT_Wunused_value); + if (rval == data_addr && TREE_CODE (alloc_expr) == TARGET_EXPR) /* If we don't have an initializer or a cookie, strip the TARGET_EXPR and return the call (which doesn't need to be adjusted). */ diff --git a/gcc/testsuite/g++.dg/warn/Wunused-value-1.C b/gcc/testsuite/g++.dg/warn/Wunused-value-1.C new file mode 100644 index 00000000000..2ba5587fce0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-value-1.C @@ -0,0 +1,12 @@ +// PR c++/107797 +// { dg-do compile { target c++11 } } +// { dg-options "-Wunused" } + +void +g () +{ + (long) new int{}; + long(new int{}); + (long) new int(); + long(new int()); +}
reply other threads:[~2023-01-23 21:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230123214225.A98283858D33@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).