This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix C++ -Wunused with empty classes (regression from 3.0.x)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: jason at redhat dot com, mark at codesourcery dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 13 Mar 2002 16:31:27 +0100
- Subject: [PATCH] Fix C++ -Wunused with empty classes (regression from 3.0.x)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The following patch fixes -Wunused handling with empty classes,
so that they are handled the same way non-empty classes (and the same as
empty structures in C).
This is regression from 3.0.x.
Ok to commit?
2002-03-13 Jakub Jelinek <jakub@redhat.com>
* call.c (build_over_call): Set TREE_NO_UNUSED_WARNING too.
* cvt.c (convert_to_void): Preserve TREE_NO_UNUSED_WARNING.
* g++.dg/warn/Wunused-1.C: New test.
--- gcc/cp/call.c.jj Wed Mar 13 01:47:29 2002
+++ gcc/cp/call.c Wed Mar 13 16:19:18 2002
@@ -4305,6 +4305,7 @@ build_over_call (cand, args, flags)
Ideally, the notions of having side-effects and of being
useless would be orthogonal. */
TREE_SIDE_EFFECTS (val) = 1;
+ TREE_NO_UNUSED_WARNING (val) = 1;
}
else
val = build (MODIFY_EXPR, TREE_TYPE (to), to, arg);
--- gcc/cp/cvt.c.jj Tue Feb 12 16:19:22 2002
+++ gcc/cp/cvt.c Wed Mar 13 16:24:13 2002
@@ -852,6 +852,7 @@ convert_to_void (expr, implicit)
tree t = build (COMPOUND_EXPR, TREE_TYPE (new_op1),
TREE_OPERAND (expr, 0), new_op1);
TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr);
+ TREE_NO_UNUSED_WARNING (t) = TREE_NO_UNUSED_WARNING (expr);
expr = t;
}
--- gcc/testsuite/g++.dg/warn/Wunused-1.C.jj Wed Mar 13 16:31:32 2002
+++ gcc/testsuite/g++.dg/warn/Wunused-1.C Wed Mar 13 16:31:22 2002
@@ -0,0 +1,15 @@
+// Test whether -Wunused handles empty classes the same as non-empty.
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+struct A {};
+struct B { char c; };
+
+void foo ()
+{
+ struct A a0, a1;
+ struct B b0, b1 = { 25 };
+
+ a0 = a1; // { dg-bogus "value computed is not used" }
+ b0 = b1;
+}
Jakub