Commit 3b4441db by Dodji Seketeli Committed by Dodji Seketeli

PR c++/29028 - Missed unused warning on using declaration

In the example of the patch, g++ fails to warn that the variable N::i
(introduced via a using declaration) is unused.

This is because as we want to emit the warning in poplevel, when we
walk the local bindings returned by getdecls, we forget that a
VAR_DECL introduced by a using declaration is represented by a
TREE_LIST which TREE_VALUE is the VAR_DECL, and we wrongly look for a
bare VAR_DECL.

Fixed thus and tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp/

	* decl.c (poplevel<warn_unused*>): Do not forget that some local
	bindings are represented by a TREE_LIST.

gcc/testsuite/

	* g++.dg/warn/Wunused-var-18.C: New test.

From-SVN: r191829
parent 2be9064d
2012-09-25 Dodji Seketeli <dodji@redhat.com>
PR c++/29028 - Missed unused warning on using declaration
* decl.c (poplevel<warn_unused*>): Do not forget that some local
bindings are represented by a TREE_LIST.
2012-09-25 Dodji Seketeli <dodji@redhat.com>
PR c++/53551 - -Wunused-local-typedefs misses uses
* decl.c (make_typename_type): Record the use of typedefs.
......
......@@ -617,7 +617,12 @@ poplevel (int keep, int reverse, int functionbody)
/* Before we remove the declarations first check for unused variables. */
if ((warn_unused_variable || warn_unused_but_set_variable)
&& !processing_template_decl)
for (decl = getdecls (); decl; decl = TREE_CHAIN (decl))
for (tree d = getdecls (); d; d = TREE_CHAIN (d))
{
/* There are cases where D itself is a TREE_LIST. See in
push_local_binding where the list of decls returned by
getdecls is built. */
decl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
if (TREE_CODE (decl) == VAR_DECL
&& (! TREE_USED (decl) || !DECL_READ_P (decl))
&& ! DECL_IN_SYSTEM_HEADER (decl)
......@@ -637,6 +642,7 @@ poplevel (int keep, int reverse, int functionbody)
unused_but_set_errorcount = errorcount;
}
}
}
/* Remove declarations for all the DECLs in this level. */
for (link = decls; link; link = TREE_CHAIN (link))
......
2012-09-25 Dodji Seketeli <dodji@redhat.com>
PR c++/29028 - Missed unused warning on using declaration
* g++.dg/warn/Wunused-var-18.C: New test.
2012-09-25 Dodji Seketeli <dodji@redhat.com>
PR c++/53551 - -Wunused-local-typedefs misses uses
* g++.dg/warn/Wunused-local-typedefs-2.C: New test.
......
// Origin: PR c++/29028
// { dg-options "-Wunused" }
// { dg-do compile }
namespace N
{
int i; // { dg-warning "unused variable" }
}
void
f ()
{
using N::i;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment