summaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>2012-09-28 12:51:30 +0000
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>2012-09-28 12:51:30 +0000
commit48b74882d1b2639b02884681a82aa2be592052b2 (patch)
tree62e97833b7985d32ad245d045f3f22483e828606 /gcc/cp/decl.c
parente3b5825b898ac1e299c2d42bb335e3528d368de7 (diff)
downloadgcc-48b74882d1b2639b02884681a82aa2be592052b2.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@191829 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a7bb9379c36..078b1486615 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -617,26 +617,32 @@ 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))
- if (TREE_CODE (decl) == VAR_DECL
- && (! TREE_USED (decl) || !DECL_READ_P (decl))
- && ! DECL_IN_SYSTEM_HEADER (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_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
- && errorcount == unused_but_set_errorcount)
- {
- warning (OPT_Wunused_but_set_variable,
- "variable %q+D set but not used", decl);
- unused_but_set_errorcount = errorcount;
- }
- }
+ 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)
+ && 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_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
+ && errorcount == unused_but_set_errorcount)
+ {
+ warning (OPT_Wunused_but_set_variable,
+ "variable %q+D set but not used", decl);
+ unused_but_set_errorcount = errorcount;
+ }
+ }
+ }
/* Remove declarations for all the DECLs in this level. */
for (link = decls; link; link = TREE_CHAIN (link))