]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 12 Jun 2013 21:36:36 +0000 (21:36 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 12 Jun 2013 21:36:36 +0000 (21:36 +0000)
2013-06-12  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/38958
* decl.c (poplevel): For the benefit of -Wunused-variable see
through references.

/testsuite
2013-06-12  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/38958
* g++.dg/warn/Wunused-var-20.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200042 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-var-20.C [new file with mode: 0644]

index 2c9398288cd00f719a357cea642ce77ab52f9697..48a9310bddcc80af118182f06719fecd6101af73 100644 (file)
@@ -1,3 +1,9 @@
+2013-06-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/38958
+       * decl.c (poplevel): For the benefit of -Wunused-variable see
+       through references.
+
 2013-06-12  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * parser.c (cp_parser_nested_name_specifier_opt): Fix typo in comment.
index 7825c73e0d7e061f3d41ac33a08fc5f9b1866940..9eb1d12ceb2ed411f9c4d17b0f881510de027db5 100644 (file)
@@ -622,17 +622,20 @@ poplevel (int keep, int reverse, int functionbody)
           push_local_binding where the list of decls returned by
           getdecls is built.  */
        decl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
+       // See through references for improved -Wunused-variable (PR 38958).
+       tree type = non_reference (TREE_TYPE (decl));
        if (VAR_P (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))))
+           && type != error_mark_node
+           && (!CLASS_TYPE_P (type)
+               || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)))
          {
            if (! TREE_USED (decl))
              warning (OPT_Wunused_variable, "unused variable %q+D", decl);
            else if (DECL_CONTEXT (decl) == current_function_decl
+                    // For -Wunused-but-set-variable leave references alone.
                     && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
                     && errorcount == unused_but_set_errorcount)
              {
index 51143cbdad1fa9f39113bd1b9d18ba2a1507141c..b167e4c3d479622582c705fcb446b442317b0435 100644 (file)
@@ -1,3 +1,8 @@
+2013-06-12  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/38958
+       * g++.dg/warn/Wunused-var-20.C: New.
+
 2013-06-12  Richard Sandiford  <rdsandiford@googlemail.com>
 
        * gcc.target/mips/mips.exp: Handle -f{no-,}common.
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-20.C b/gcc/testsuite/g++.dg/warn/Wunused-var-20.C
new file mode 100644 (file)
index 0000000..792c253
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/38958
+// { dg-options "-Wunused" }
+
+volatile int g;
+
+struct Lock
+{
+  ~Lock() { g = 0; }
+};
+
+Lock AcquireLock() { return Lock(); }
+
+int main()
+{
+  const Lock& lock = AcquireLock();
+  g = 1;
+  g = 2;
+  g = 3;
+}