* [pushed] c++: -Wunused-value and array init [PR104702]
@ 2022-04-06 15:33 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-06 15:33 UTC (permalink / raw)
To: gcc-patches
Here, because of problems with the new warning-control code and expressions
that change location, the suppress_warning on the INDIRECT_REF didn't work.
Those problems still need to be worked out, but it's simple to avoid needing
to use suppress_warning in the first place by using a reference instead.
Tested x86_64-pc-linux-gnu, applying to trunk.
PR c++/104702
gcc/cp/ChangeLog:
* init.cc (build_vec_init): Use a reference for the result.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wunused-19.C: New test.
---
gcc/cp/init.cc | 5 ++---
gcc/testsuite/g++.dg/warn/Wunused-19.C | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-19.C
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 01e762320f3..c20ed211f1d 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4908,10 +4908,9 @@ build_vec_init (tree base, tree maxindex, tree init,
/* Now make the result have the correct type. */
if (TREE_CODE (atype) == ARRAY_TYPE)
{
- atype = build_pointer_type (atype);
+ atype = build_reference_type (atype);
stmt_expr = build1 (NOP_EXPR, atype, stmt_expr);
- stmt_expr = cp_build_fold_indirect_ref (stmt_expr);
- suppress_warning (stmt_expr /* What warning? */);
+ stmt_expr = convert_from_reference (stmt_expr);
}
return stmt_expr;
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-19.C b/gcc/testsuite/g++.dg/warn/Wunused-19.C
new file mode 100644
index 00000000000..2fc70b04c18
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wunused-19.C
@@ -0,0 +1,16 @@
+// PR c++/104702
+// { dg-additional-options "-fno-exceptions -Wunused-value" }
+
+struct FlyString {
+ FlyString(char const*);
+ ~FlyString();
+};
+
+struct Array { FlyString __data[1]; };
+
+void frobnicate(Array&);
+
+int main() {
+ Array s_reserved_words = { "" }; // { dg-bogus "value computed is not used" }
+ frobnicate(s_reserved_words);
+}
base-commit: eac5c12c1838d51bf05bd6f30f3f5d7bb760e398
--
2.27.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-06 15:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 15:33 [pushed] c++: -Wunused-value and array init [PR104702] Jason Merrill
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).