* [C++ Patch] PR 10416
@ 2012-08-20 14:15 Paolo Carlini
2012-08-20 17:16 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2012-08-20 14:15 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 459 bytes --]
Hi,
in this old issue submitter points out that we emit too easily
Wunused_variable warnings even when the destructor has side effects
(otoh, the constructor is handled Ok). This is particularly annoying
together with eg, RAII.
Turns out that lately we are already careful when we handle the new
Wunused_but_set_variable, thus I'm simply proposing to commonize the
additional check.
Tested x86_64-linux.
Thanks,
Paolo.
/////////////////////////////
[-- Attachment #2: CL_10416 --]
[-- Type: text/plain, Size: 278 bytes --]
/cp
2012-08-20 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/10416
* decl.c (poplevel): Check TYPE_HAS_NONTRIVIAL_DESTRUCTOR for
Wunused_variable too.
/testsuite
2012-08-20 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/10416
* g++.dg/warn/Wunused-var-17.C: New.
[-- Attachment #3: patch_10416 --]
[-- Type: text/plain, Size: 1548 bytes --]
Index: testsuite/g++.dg/warn/Wunused-var-17.C
===================================================================
--- testsuite/g++.dg/warn/Wunused-var-17.C (revision 0)
+++ testsuite/g++.dg/warn/Wunused-var-17.C (revision 0)
@@ -0,0 +1,4 @@
+// PR c++/10416
+// { dg-options "-Wunused" }
+
+void f () { struct atend { ~atend () { __builtin_printf("leaving f\n"); } } a; }
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 190526)
+++ cp/decl.c (working copy)
@@ -621,16 +621,16 @@ poplevel (int keep, int reverse, int functionbody)
if (TREE_CODE (decl) == VAR_DECL
&& (! TREE_USED (decl) || !DECL_READ_P (decl))
&& ! DECL_IN_SYSTEM_HEADER (decl)
- && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
+ && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)
+ && TREE_TYPE (decl) != error_mark_node
+ && (!CLASS_TYPE_P (TREE_TYPE (decl))
+ || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
{
if (! TREE_USED (decl))
warning (OPT_Wunused_variable, "unused variable %q+D", decl);
else if (DECL_CONTEXT (decl) == current_function_decl
- && TREE_TYPE (decl) != error_mark_node
&& TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
- && errorcount == unused_but_set_errorcount
- && (!CLASS_TYPE_P (TREE_TYPE (decl))
- || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
+ && errorcount == unused_but_set_errorcount)
{
warning (OPT_Wunused_but_set_variable,
"variable %q+D set but not used", decl);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-20 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-20 14:15 [C++ Patch] PR 10416 Paolo Carlini
2012-08-20 17:16 ` 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).