public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix -Wunused-* regression (PR c++/71442)
@ 2016-06-07 15:23 Jakub Jelinek
  2016-06-08 12:40 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2016-06-07 15:23 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

Marek has recently added code to set TREE_USED bits on the elements of
TREE_VEC referenced in SIZEOF_EXPR.
But, as the testcase shows, it can be used on various parameter/argument
packs, some of them have types as elements, others decls.
And IMHO we want to set TREE_USED only on the decls listed in those,
for types TREE_USED should be a property of the type regardless of whether
the type is mentioned in sizeof... or not, otherwise we suddenly stop
diagnosing any unused vars with those types.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2/5.5?

2016-06-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/71442
	* pt.c (tsubst_copy): Only set TREE_USED on DECLs.

	* g++.dg/cpp0x/Wunused-variable-1.C: New test.

--- gcc/cp/pt.c.jj	2016-06-01 14:17:12.000000000 +0200
+++ gcc/cp/pt.c	2016-06-07 14:29:16.608041125 +0200
@@ -14160,7 +14160,8 @@ tsubst_copy (tree t, tree args, tsubst_f
 	      len = TREE_VEC_LENGTH (expanded);
 	      /* Set TREE_USED for the benefit of -Wunused.  */
 	      for (int i = 0; i < len; i++)
-		TREE_USED (TREE_VEC_ELT (expanded, i)) = true;
+		if (DECL_P (TREE_VEC_ELT (expanded, i)))
+		  TREE_USED (TREE_VEC_ELT (expanded, i)) = true;
 	    }
 
 	  if (expanded == error_mark_node)
--- gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C.jj	2016-06-07 14:31:15.514486508 +0200
+++ gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C	2016-06-07 14:32:13.526730026 +0200
@@ -0,0 +1,25 @@
+// PR c++/71442
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-variable" }
+
+struct C
+{
+  template<typename... Ts>
+  int operator()(Ts &&...)
+  {
+    return sizeof...(Ts);
+  }
+};
+
+int
+main ()
+{
+  C {} (1, 1L, 1LL, 1.0);
+  char a;		// { dg-warning "unused variable" }
+  short b;		// { dg-warning "unused variable" }
+  int c;		// { dg-warning "unused variable" }
+  long d;		// { dg-warning "unused variable" }
+  long long e;		// { dg-warning "unused variable" }
+  float f;		// { dg-warning "unused variable" }
+  double g;		// { dg-warning "unused variable" }
+}

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ PATCH] Fix -Wunused-* regression (PR c++/71442)
  2016-06-07 15:23 [C++ PATCH] Fix -Wunused-* regression (PR c++/71442) Jakub Jelinek
@ 2016-06-08 12:40 ` Jakub Jelinek
  2016-06-08 17:53   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2016-06-08 12:40 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On Tue, Jun 07, 2016 at 05:23:34PM +0200, Jakub Jelinek wrote:
> Marek has recently added code to set TREE_USED bits on the elements of
> TREE_VEC referenced in SIZEOF_EXPR.
> But, as the testcase shows, it can be used on various parameter/argument
> packs, some of them have types as elements, others decls.
> And IMHO we want to set TREE_USED only on the decls listed in those,
> for types TREE_USED should be a property of the type regardless of whether
> the type is mentioned in sizeof... or not, otherwise we suddenly stop
> diagnosing any unused vars with those types.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2/5.5?
> 
> 2016-06-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/71442
> 	* pt.c (tsubst_copy): Only set TREE_USED on DECLs.
> 
> 	* g++.dg/cpp0x/Wunused-variable-1.C: New test.

Richi pointed in the PR that I've screwed up the testcase, it doesn't FAIL
with unpatched compiler.

Here is the same patch with slightly adjusted testcase that does fail
with unpatched trunk, 6.1 or 5.4.  Bootstrapped/regtested again on
x86_64-linux and i686-linux, ok for trunk/6.2/5.5?

2016-06-08  Jakub Jelinek  <jakub@redhat.com>

	PR c++/71442
	* pt.c (tsubst_copy): Only set TREE_USED on DECLs.

	* g++.dg/cpp0x/Wunused-variable-1.C: New test.

--- gcc/cp/pt.c.jj	2016-06-01 14:17:12.000000000 +0200
+++ gcc/cp/pt.c	2016-06-07 14:29:16.608041125 +0200
@@ -14160,7 +14160,8 @@ tsubst_copy (tree t, tree args, tsubst_f
 	      len = TREE_VEC_LENGTH (expanded);
 	      /* Set TREE_USED for the benefit of -Wunused.  */
 	      for (int i = 0; i < len; i++)
-		TREE_USED (TREE_VEC_ELT (expanded, i)) = true;
+		if (DECL_P (TREE_VEC_ELT (expanded, i)))
+		  TREE_USED (TREE_VEC_ELT (expanded, i)) = true;
 	    }
 
 	  if (expanded == error_mark_node)
--- gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C.jj	2016-06-07 14:31:15.514486508 +0200
+++ gcc/testsuite/g++.dg/cpp0x/Wunused-variable-1.C	2016-06-07 14:32:13.526730026 +0200
@@ -0,0 +1,37 @@
+// PR c++/71442
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused-variable" }
+
+struct C
+{
+  template<typename... Ts>
+  int operator()(Ts &&...)
+  {
+    return sizeof...(Ts);
+  }
+};
+
+int
+foo ()
+{
+  C {} (1, 1L, 1LL, 1.0);
+}
+
+template<int N>
+void
+bar ()
+{
+  char a;		// { dg-warning "unused variable" }
+  short b;		// { dg-warning "unused variable" }
+  int c;		// { dg-warning "unused variable" }
+  long d;		// { dg-warning "unused variable" }
+  long long e;		// { dg-warning "unused variable" }
+  float f;		// { dg-warning "unused variable" }
+  double g;		// { dg-warning "unused variable" }
+}
+
+void
+baz ()
+{
+  bar <0> ();
+}


	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ PATCH] Fix -Wunused-* regression (PR c++/71442)
  2016-06-08 12:40 ` Jakub Jelinek
@ 2016-06-08 17:53   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2016-06-08 17:53 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

OK.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-08 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-07 15:23 [C++ PATCH] Fix -Wunused-* regression (PR c++/71442) Jakub Jelinek
2016-06-08 12:40 ` Jakub Jelinek
2016-06-08 17:53   ` 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).