PR c++/44108

Dodji Seketeli dodji@redhat.com
Mon May 17 16:28:00 GMT 2010


Hello Jason,

In the example of the patch below we fail to mark the use of the
const variables as being rvalue use, when the variables are used as
array size in the declarations.

Thus the patch below marks that use. You have already OKed that patch
on IRC for trunk but I am posting it gcc-patches nonetheless.

The second patch (in attachment) is for the applicable branches. It
disables the -Wunused_but_set_variable warning for integral constant
variables as those cannot be set anyway. Jakub explained that in the
comments of the PR. You OKed that patch for the branch too.

Jakub agreed to help me regtest both patches on a beefier box than
mine, so that it can be done quickly. I will commit the patches when
the regression test passes.

Thanks.

commit c91060c41b83c31b078dd0f236d0d4e865aefe9b
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Mon May 17 17:07:29 2010 +0200

    Fix PR c++/44108
    
    gcc/cp/ChangeLog:
    	PR c++/44108
    	* decl.c (compute_array_index_type): Mark the use of size as an
    	rvalue use.
    
    gcc/testsuite/ChangeLog:
    	PR c++/44108
    	* c-c++-common/Wunused-var-8.c: New test.


diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 148bcf5..0636aba 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7369,6 +7369,8 @@ compute_array_index_type (tree name, tree size)
   /* The size might be the result of a cast.  */
   STRIP_TYPE_NOPS (size);
 
+  size = mark_rvalue_use (size);
+
   /* It might be a const variable or enumeration constant.  */
   size = integral_constant_value (size);
   if (error_operand_p (size))
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-8.c b/gcc/testsuite/c-c++-common/Wunused-var-8.c
new file mode 100644
index 0000000..c1aa25a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wunused-var-8.c
@@ -0,0 +1,22 @@
+/* Origin: PR c++/44108 */
+/* { dg-options "-Wunused" } */
+/* { dg-do compile } */
+
+int
+main (int argc, char *argv[])
+{
+  unsigned int M              = 2;
+  const unsigned int M_CONST        = 2;
+  static       unsigned int M_STATIC       = 2;
+  static const unsigned int M_STATIC_CONST = 2;
+
+  char resolved_name1[M];
+  char resolved_name2[M_CONST];
+  char resolved_name3[M_STATIC];
+  char resolved_name4[M_STATIC_CONST];
+
+  return sizeof (resolved_name1)
+    + sizeof (resolved_name2)
+    + sizeof (resolved_name3)
+    + sizeof (resolved_name4);
+}


        Dodji
-------------- next part --------------
commit 7472832f395b4717b492b728db08139e9c7a14a9
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Mon May 17 17:07:29 2010 +0200

    Fix PR c++/44108
    
    gcc/cp/ChangeLog
    	PR c++/44108
    	* decl.c (poplevel): When -Wunused_but_set_variable is in effect,
    	do not warn for integral constant variables.
    
    gcc/testsuite/ChangeLog:
    	PR c++/44108
    	* c-c++-common/Wunused-var-8.c: New test.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 148bcf5..bf0ad42 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -606,6 +606,7 @@ poplevel (int keep, int reverse, int functionbody)
 	    warning (OPT_Wunused_variable, "unused variable %q+D", decl);
 	  else if (DECL_CONTEXT (decl) == current_function_decl
 		   && TREE_TYPE (decl) != error_mark_node
+		   && !DECL_INTEGRAL_CONSTANT_VAR_P (decl)
 		   && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
 		   && errorcount == unused_but_set_errorcount
 		   && (!CLASS_TYPE_P (TREE_TYPE (decl))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b4d89e0..3007bb2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
diff --git a/gcc/testsuite/c-c++-common/Wunused-var-8.c b/gcc/testsuite/c-c++-common/Wunused-var-8.c
new file mode 100644
index 0000000..c1aa25a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wunused-var-8.c
@@ -0,0 +1,22 @@
+/* Origin: PR c++/44108 */
+/* { dg-options "-Wunused" } */
+/* { dg-do compile } */
+
+int
+main (int argc, char *argv[])
+{
+  unsigned int M              = 2;
+  const unsigned int M_CONST        = 2;
+  static       unsigned int M_STATIC       = 2;
+  static const unsigned int M_STATIC_CONST = 2;
+
+  char resolved_name1[M];
+  char resolved_name2[M_CONST];
+  char resolved_name3[M_STATIC];
+  char resolved_name4[M_STATIC_CONST];
+
+  return sizeof (resolved_name1)
+    + sizeof (resolved_name2)
+    + sizeof (resolved_name3)
+    + sizeof (resolved_name4);
+}


More information about the Gcc-patches mailing list