This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Updated C++ FE -Wunused-but-set-{variable,parameter} patch


Hi!

Here is an updated patch for the C++ -Wunused-but-set-{parameter,variable}
support.  Haven't done any changes Jason requested though, just updated
the patch to apply cleanly and reshuffled the tests, so that the ones
that can be shared between C and C++ live in c-c++-common.

The patch is on top of
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00347.html
and this time has just been tested with make check
RUNTESTFLAGS=dg.exp=*used*

2010-04-08  Jakub Jelinek  <jakub@redhat.com>

	PR c/18624
	* cp-tree.h (mark_exp_read): New prototype.
	* typeck.c (mark_exp_read): New function.
	(cxx_sizeof_expr, cxx_alignof_expr, decay_conversion,
	perform_integral_promotions, cp_build_unary_op): Call it.
	* decl.c (unused_but_set_errorcount): New variable.
	(poplevel): Issue -Wunused-but-set-variable diagnostics.
	(duplicate_decls): Merge DECL_READ_P flags.
	(start_cleanup_fn): Set DECL_READ_P flag.
	(finish_function): Issue -Wunused-but-set-parameter diagnostics.
	* tree.c (rvalue): Call mark_exp_read.
	* pt.c (convert_nontype_argument): Likewise.
	* semantics.c (finish_expr_stmt, finish_asm_stmt, finish_typeof,
	finish_decltype_type): Likewise.
	* call.c (convert_like_real, build_x_va_arg, build_over_call,
	build_new_method_call): Likewise.
	* init.c (build_new, build_delete): Likewise.
	* rtti.c (build_typeid, build_dynamic_cast_1): Likewise.

	* g++.dg/warn/Wunused-7.C: Add dg-warning.
	* g++.dg/template/sfinae16.C: Likewise.
	* gcc.dg/Wunused-var-1.c: Moved to...
	* c-c++-common/Wunused-var-1.c: ...here. New test.
	* gcc.dg/Wunused-var-2.c: Moved to...
	* c-c++-common/Wunused-var-2.c: ...here. New test.
	* gcc.dg/Wunused-var-3.c: Moved to...
	* c-c++-common/Wunused-var-3.c: ...here. New test.
	* gcc.dg/Wunused-var-4.c: Moved to...
	* gcc.dg/Wunused-var-1.c: ... here.
	* gcc.dg/Wunused-var-5.c: Moved to...
	* c-c++-common/Wunused-var-4.c: ...here. New test.
	* gcc.dg/Wunused-var-7.c: Moved to...
	* c-c++-common/Wunused-var-5.c: ...here. New test.
	* gcc.dg/Wunused-var-6.c: Moved to...
	* gcc.dg/Wunused-var-2.c: ... here.
	* c-c++-common/Wunused-var-1.c: New test.
	* c-c++-common/Wunused-var-2.c: New test.
	* c-c++-common/Wunused-var-3.c: New test.
	* c-c++-common/Wunused-var-4.c: New test.
	* c-c++-common/Wunused-var-5.c: New test.
	* g++.dg/warn/Wunused-var-1.C: New test.
	* g++.dg/warn/Wunused-var-2.C: New test.
	* g++.dg/warn/Wunused-var-3.C: New test.
	* g++.dg/warn/Wunused-var-4.C: New test.
	* g++.dg/warn/Wunused-var-5.C: New test.
	* g++.dg/warn/Wunused-var-6.C: New test.
	* g++.dg/warn/Wunused-var-7.C: New test.
	* g++.dg/warn/Wunused-var-8.C: New test.
	* g++.dg/warn/Wunused-parm-1.C: New test.
	* g++.dg/warn/Wunused-parm-2.C: New test.
	* g++.dg/warn/Wunused-parm-3.C: New test.

--- gcc/cp/tree.c.jj	2010-04-07 19:54:51.000000000 +0200
+++ gcc/cp/tree.c	2010-04-08 16:15:09.000000000 +0200
@@ -548,6 +548,8 @@ rvalue (tree expr)
 {
   tree type;
 
+  mark_exp_read (expr);
+
   if (error_operand_p (expr))
     return expr;
 
--- gcc/cp/init.c.jj	2010-01-22 17:23:43.000000000 +0100
+++ gcc/cp/init.c	2010-04-08 16:15:08.000000000 +0200
@@ -2361,6 +2361,7 @@ build_new (VEC(tree,gc) **placement, tre
           else
             return error_mark_node;
         }
+      mark_exp_read (nelts);
       nelts = cp_save_expr (cp_convert (sizetype, nelts));
     }
 
@@ -3016,6 +3017,8 @@ build_delete (tree type, tree addr, spec
 
   type = TYPE_MAIN_VARIANT (type);
 
+  mark_exp_read (addr);
+
   if (TREE_CODE (type) == POINTER_TYPE)
     {
       bool complete_p = true;
--- gcc/cp/rtti.c.jj	2010-01-22 17:23:43.000000000 +0100
+++ gcc/cp/rtti.c	2010-04-08 16:15:09.000000000 +0200
@@ -327,6 +327,8 @@ build_typeid (tree exp)
   if (processing_template_decl)
     return build_min (TYPEID_EXPR, const_type_info_type_node, exp);
 
+  mark_exp_read (exp);
+
   if (TREE_CODE (exp) == INDIRECT_REF
       && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
       && TYPE_POLYMORPHIC_P (TREE_TYPE (exp))
@@ -515,6 +517,8 @@ build_dynamic_cast_1 (tree type, tree ex
   /* Save casted types in the function's used types hash table.  */
   used_types_insert (type);
 
+  mark_exp_read (expr);
+
   /* T shall be a pointer or reference to a complete class type, or
      `pointer to cv void''.  */
   switch (tc)
--- gcc/cp/decl.c.jj	2010-04-08 09:34:41.000000000 +0200
+++ gcc/cp/decl.c	2010-04-08 16:16:20.000000000 +0200
@@ -498,6 +498,10 @@ poplevel_named_label_1 (void **slot, voi
   return 1;
 }
 
+/* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
+   when errors were reported, except for -Werror-unused-but-set-*.  */
+static int unused_but_set_errorcount;
+
 /* Exit a binding level.
    Pop the level off, and restore the state of the identifier-decl mappings
    that were in effect when this level was entered.
@@ -589,14 +593,28 @@ poplevel (int keep, int reverse, int fun
     = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
 
   /* Before we remove the declarations first check for unused variables.  */
-  if (warn_unused_variable
+  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)
+	  && (! TREE_USED (decl) || !DECL_READ_P (decl))
 	  && ! DECL_IN_SYSTEM_HEADER (decl)
 	  && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
-	warning (OPT_Wunused_variable, "unused variable %q+D", decl);
+	{
+	  if (! TREE_USED (decl))
+	    warning (OPT_Wunused_variable, "unused variable %q+D", decl);
+	  else if (DECL_CONTEXT (decl) == current_function_decl
+		   && TREE_TYPE (decl) != error_mark_node
+		   && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
+		   && errorcount == unused_but_set_errorcount
+		   && (!CLASS_TYPE_P (TREE_TYPE (decl))
+		       || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
+	    {
+	      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))
@@ -2096,6 +2114,13 @@ duplicate_decls (tree newdecl, tree oldd
     TREE_USED (newdecl) = 1;
   else if (TREE_USED (newdecl))
     TREE_USED (olddecl) = 1;
+  if (TREE_CODE (newdecl) == VAR_DECL)
+    {
+      if (DECL_READ_P (olddecl))
+	DECL_READ_P (newdecl) = 1;
+      else if (DECL_READ_P (newdecl))
+	DECL_READ_P (olddecl) = 1;
+    }
   if (DECL_PRESERVE_P (olddecl))
     DECL_PRESERVE_P (newdecl) = 1;
   else if (DECL_PRESERVE_P (newdecl))
@@ -6161,6 +6186,7 @@ start_cleanup_fn (void)
       parmdecl = cp_build_parm_decl (NULL_TREE, ptr_type_node);
       DECL_CONTEXT (parmdecl) = fndecl;
       TREE_USED (parmdecl) = 1;
+      DECL_READ_P (parmdecl) = 1;
       DECL_ARGUMENTS (fndecl) = parmdecl;
     }
 
@@ -12570,6 +12596,33 @@ finish_function (int flags)
      info for the epilogue.  */
   cfun->function_end_locus = input_location;
 
+  /* Complain about parameters that are only set, but never otherwise used.  */
+  if (warn_unused_but_set_parameter
+      && !processing_template_decl
+      && errorcount == unused_but_set_errorcount
+      && !DECL_CLONED_FUNCTION_P (fndecl))
+    {
+      tree decl;
+
+      for (decl = DECL_ARGUMENTS (fndecl);
+	   decl;
+	   decl = TREE_CHAIN (decl))
+	if (TREE_USED (decl)
+	    && TREE_CODE (decl) == PARM_DECL
+	    && !DECL_READ_P (decl)
+	    && DECL_NAME (decl)
+	    && !DECL_ARTIFICIAL (decl)
+	    && !TREE_NO_WARNING (decl)
+	    && !DECL_IN_SYSTEM_HEADER (decl)
+	    && TREE_TYPE (decl) != error_mark_node
+	    && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
+	    && (!CLASS_TYPE_P (TREE_TYPE (decl))
+	        || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
+	  warning (OPT_Wunused_but_set_parameter,
+		   "parameter %q+D set but not used", decl);
+      unused_but_set_errorcount = errorcount;
+    }
+
   /* Genericize before inlining.  */
   if (!processing_template_decl)
     {
--- gcc/cp/call.c.jj	2010-04-01 21:42:23.000000000 +0200
+++ gcc/cp/call.c	2010-04-08 16:15:09.000000000 +0200
@@ -4886,6 +4886,8 @@ convert_like_real (conversion *convs, tr
 	tree convfn = cand->fn;
 	unsigned i;
 
+	mark_exp_read (expr);
+
 	/* When converting from an init list we consider explicit
 	   constructors, but actually trying to call one is an error.  */
 	if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn))
@@ -4918,6 +4920,7 @@ convert_like_real (conversion *convs, tr
 	return expr;
       }
     case ck_identity:
+      mark_exp_read (expr);
       if (BRACE_ENCLOSED_INITIALIZER_P (expr))
 	{
 	  int nelts = CONSTRUCTOR_NELTS (expr);
@@ -5240,6 +5243,8 @@ build_x_va_arg (tree expr, tree type)
       return expr;
     }
 
+  mark_exp_read (expr);
+
   return build_va_arg (input_location, expr, type);
 }
 
@@ -5694,7 +5699,8 @@ build_over_call (struct z_candidate *can
     {
       tree a = VEC_index (tree, args, arg_index);
       if (magic_varargs_p (fn))
-	/* Do no conversions for magic varargs.  */;
+	/* Do no conversions for magic varargs.  */
+	mark_exp_read (a);
       else
 	a = convert_arg_to_ellipsis (a);
       argarray[j++] = a;
@@ -6256,6 +6262,8 @@ build_new_method_call (tree instance, tr
       if (args != NULL)
 	make_args_non_dependent (*args);
     }
+  else
+    mark_exp_read (instance);
 
   user_args = args == NULL ? NULL : *args;
   /* Under DR 147 A::A() is an invalid constructor call,
--- gcc/cp/semantics.c.jj	2010-04-07 19:54:51.000000000 +0200
+++ gcc/cp/semantics.c	2010-04-08 16:15:08.000000000 +0200
@@ -610,6 +610,8 @@ finish_expr_stmt (tree expr)
 	{
 	  if (warn_sequence_point)
 	    verify_sequence_points (expr);
+	  if (TREE_CODE (expr) != MODIFY_EXPR)
+	    mark_exp_read (expr);
 	  expr = convert_to_void (expr, "statement", tf_warning_or_error);
 	}
       else if (!type_dependent_expression_p (expr))
@@ -1238,6 +1240,8 @@ finish_asm_stmt (int volatile_p, tree st
 	     otherwise we'll get an error.  Gross, but ...  */
 	  STRIP_NOPS (operand);
 
+	  mark_exp_read (operand);
+
 	  if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
 	    operand = error_mark_node;
 
@@ -3227,6 +3231,8 @@ finish_typeof (tree expr)
       return type;
     }
 
+  mark_exp_read (expr);
+
   type = unlowered_expr_type (expr);
 
   if (!type || type == unknown_type_node)
@@ -4888,6 +4894,12 @@ finish_decltype_type (tree expr, bool id
 
       switch (TREE_CODE (expr))
         {
+        case VAR_DECL:
+        case PARM_DECL:
+	  mark_exp_read (expr);
+          type = TREE_TYPE (expr);
+          break;
+
         case FIELD_DECL:
           if (DECL_BIT_FIELD_TYPE (expr))
             {
@@ -4897,9 +4909,7 @@ finish_decltype_type (tree expr, bool id
           /* Fall through for fields that aren't bitfields.  */
 
         case FUNCTION_DECL:
-        case VAR_DECL:
         case CONST_DECL:
-        case PARM_DECL:
         case RESULT_DECL:
         case TEMPLATE_PARM_INDEX:
           type = TREE_TYPE (expr);
@@ -4910,6 +4920,7 @@ finish_decltype_type (tree expr, bool id
           break;
 
         case COMPONENT_REF:
+	  mark_exp_read (expr);
           type = is_bitfield_expr_with_lowered_type (expr);
           if (!type)
             type = TREE_TYPE (TREE_OPERAND (expr, 1));
--- gcc/cp/pt.c.jj	2010-04-07 19:54:51.000000000 +0200
+++ gcc/cp/pt.c	2010-04-08 16:15:08.000000000 +0200
@@ -4924,6 +4924,7 @@ convert_nontype_argument (tree type, tre
   if (error_operand_p (expr))
     return error_mark_node;
   expr_type = TREE_TYPE (expr);
+  mark_exp_read (expr);
 
   /* HACK: Due to double coercion, we can get a
      NOP_EXPR<REFERENCE_TYPE>(ADDR_EXPR<POINTER_TYPE> (arg)) here,
--- gcc/cp/cp-tree.h.jj	2010-04-07 19:54:51.000000000 +0200
+++ gcc/cp/cp-tree.h	2010-04-08 16:15:08.000000000 +0200
@@ -5420,6 +5420,7 @@ extern tree convert_ptrmem			(tree, tree
 extern int lvalue_or_else			(tree, enum lvalue_use,
                                                  tsubst_flags_t);
 extern void check_template_keyword		(tree);
+extern void mark_exp_read			(tree);
 
 /* in typeck2.c */
 extern void require_complete_eh_spec_types	(tree, tree);
--- gcc/cp/typeck.c.jj	2010-04-07 19:54:51.000000000 +0200
+++ gcc/cp/typeck.c	2010-04-08 16:15:09.000000000 +0200
@@ -1616,6 +1616,8 @@ cxx_sizeof_expr (tree e, tsubst_flags_t 
       && DECL_TEMPLATE_INSTANTIATION (e))
     instantiate_decl (e, /*defer_ok*/true, /*expl_inst_mem*/false);
 
+  mark_exp_read (e);
+
   if (TREE_CODE (e) == COMPONENT_REF
       && TREE_CODE (TREE_OPERAND (e, 1)) == FIELD_DECL
       && DECL_C_BIT_FIELD (TREE_OPERAND (e, 1)))
@@ -1671,6 +1673,8 @@ cxx_alignof_expr (tree e, tsubst_flags_t
       return e;
     }
 
+  mark_exp_read (e);
+
   if (TREE_CODE (e) == VAR_DECL)
     t = size_int (DECL_ALIGN_UNIT (e));
   else if (TREE_CODE (e) == COMPONENT_REF
@@ -1837,6 +1841,8 @@ decay_conversion (tree exp)
   if (type == error_mark_node)
     return error_mark_node;
 
+  mark_exp_read (exp);
+
   exp = resolve_nondeduced_context (exp);
   if (type_unknown_p (exp))
     {
@@ -1961,6 +1967,8 @@ perform_integral_promotions (tree expr)
   tree type;
   tree promoted_type;
 
+  mark_exp_read (expr);
+
   /* [conv.prom]
 
      If the bitfield has an enumerated type, it is treated as any
@@ -4785,6 +4793,8 @@ cp_build_unary_op (enum tree_code code, 
       if (val != 0)
 	return val;
 
+      mark_exp_read (arg);
+
       /* Increment or decrement the real part of the value,
 	 and don't change the imaginary part.  */
       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
@@ -4918,6 +4928,8 @@ cp_build_unary_op (enum tree_code code, 
 
       argtype = lvalue_type (arg);
 
+      mark_exp_read (arg);
+
       if (TREE_CODE (arg) == OFFSET_REF)
 	goto offset_ref;
 
@@ -8011,3 +8023,41 @@ lvalue_or_else (tree ref, enum lvalue_us
 
   return win;
 }
+
+/* Mark EXP as read, not just set, for set but not used -Wunused
+   warning purposes.  */
+
+void
+mark_exp_read (tree exp)
+{
+  if (exp == NULL)
+    return;
+
+  switch (TREE_CODE (exp))
+    {
+    case VAR_DECL:
+    case PARM_DECL:
+      DECL_READ_P (exp) = 1;
+      break;
+    case ARRAY_REF:
+    case COMPONENT_REF:
+    case MODIFY_EXPR:
+    case REALPART_EXPR:
+    case IMAGPART_EXPR:
+    CASE_CONVERT:
+    case ADDR_EXPR:
+      mark_exp_read (TREE_OPERAND (exp, 0));
+      break;
+    case COMPOUND_EXPR:
+      mark_exp_read (TREE_OPERAND (exp, 1));
+      break;
+    case COND_EXPR:
+      if (TREE_OPERAND (exp, 1))
+	mark_exp_read (TREE_OPERAND (exp, 1));
+      if (TREE_OPERAND (exp, 2))
+	mark_exp_read (TREE_OPERAND (exp, 2));
+      break;
+    default:
+      break;
+    }
+}
--- gcc/cp/except.c.jj	2010-01-22 17:23:43.000000000 +0100
+++ gcc/cp/except.c	2010-04-08 16:15:09.000000000 +0200
@@ -369,6 +369,7 @@ initialize_handler_parm (tree decl, tree
   /* Make sure we mark the catch param as used, otherwise we'll get a
      warning about an unused ((anonymous)).  */
   TREE_USED (decl) = 1;
+  DECL_READ_P (decl) = 1;
 
   /* Figure out the type that the initializer is.  Pointers are returned
      adjusted by value from __cxa_begin_catch.  Others are returned by
--- gcc/testsuite/gcc.dg/Wunused-var-2.c.jj	2010-04-07 22:31:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-2.c	2010-04-07 22:31:42.000000000 +0200
@@ -4,17 +4,16 @@
 int
 f1 (void)
 {
-  int c = ({
-    int a;
-    a = 1;
-    a; });
-  return c;
-}
-
-void
-f2 (void)
-{
-  int f;
-  f = 0;
-  __asm__ __volatile__ ("" : "+r" (f));
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  a = 1;
+  b = 2;
+  c = 3;
+  d = 4;
+  e = 5;
+  return sizeof (a) + ((__typeof (b)) 1) + __alignof__ (c)
+         + __builtin_choose_expr (1, d, e);
 }
--- gcc/testsuite/gcc.dg/Wunused-var-3.c.jj	2010-04-07 22:31:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-3.c	2010-04-08 16:24:24.000000000 +0200
@@ -1,37 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-Wunused" } */
-
-void
-f1 (void)
-{
-  _Complex int a;	/* { dg-warning "set but not used" } */
-  _Complex double b;	/* { dg-warning "set but not used" } */
-  __real__ a = 1;
-  __imag__ a = 2;
-  __real__ b = 3.0;
-  __imag__ b = 4.0;
-}
-
-int
-f2 (void)
-{
-  _Complex int a;
-  _Complex double b;
-  __real__ a = 1;
-  __imag__ a = 2;
-  __real__ b = 3.0;
-  __imag__ b = 4.0;
-  return __real__ a + __imag__ b;
-}
-
-_Complex double
-f3 (void)
-{
-  _Complex int a;
-  _Complex double b;
-  __real__ a = 1;
-  __imag__ a = 2;
-  __real__ b = 3.0;
-  __imag__ b = 4.0;
-  return a + b;
-}
--- gcc/testsuite/gcc.dg/Wunused-var-5.c.jj	2010-04-07 22:31:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-5.c	2010-04-08 16:24:30.000000000 +0200
@@ -1,33 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-Wunused" } */
-
-void
-f1 (void)
-{
-  extern int extvari;
-  extvari = 1;
-}
-
-int extvarj;
-
-void
-f2 (void)
-{
-  extern int extvarj;
-  extvarj = 1;
-}
-
-static int extvark;
-
-void
-f3 (void)
-{
-  extern int extvark;
-  extvark = 1;
-}
-
-int
-f4 (void)
-{
-  return extvark;
-}
--- gcc/testsuite/gcc.dg/Wunused-var-6.c.jj	2010-04-07 22:31:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-6.c	2010-04-08 16:24:33.000000000 +0200
@@ -1,19 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-Wunused" } */
-
-int
-f1 (void)
-{
-  int a;
-  int b;
-  int c;
-  int d;
-  int e;
-  a = 1;
-  b = 2;
-  c = 3;
-  d = 4;
-  e = 5;
-  return sizeof (a) + ((__typeof (b)) 1) + __alignof__ (c)
-         + __builtin_choose_expr (1, d, e);
-}
--- gcc/testsuite/gcc.dg/Wunused-var-7.c.jj	2010-04-08 16:14:50.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-7.c	2010-04-08 16:24:37.000000000 +0200
@@ -1,29 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-Wunused -W" } */
-
-int
-f1 (unsigned int x)
-{
-  int c = ({ union { unsigned int a; int b; } u; u.a = x; u.b; });
-  return c;
-}
-
-void
-f2 (void)
-{
-  struct S { int i; } a;
-  int b[1];
-  a.i = 1;
-  a.i;				/* { dg-warning "with no effect" } */
-  b[0] = 1;
-  b[0];				/* { dg-warning "with no effect" } */
-}
-
-void
-f3 (void)
-{
-  struct S { int i; } a;	/* { dg-warning "set but not used" } */
-  int b[1];			/* { dg-warning "set but not used" } */
-  a.i = 1;
-  b[0] = 1;
-}
--- gcc/testsuite/gcc.dg/Wunused-var-1.c.jj	2010-04-07 22:31:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-1.c	2010-04-07 22:31:42.000000000 +0200
@@ -1,179 +1,26 @@
 /* { dg-do compile } */
 /* { dg-options "-Wunused" } */
 
-void
-f1 (void)
-{
-  int a;	/* { dg-warning "set but not used" } */
-  int b;
-  int c;
-  c = 1;
-  a = b = c;
-}
-
-void
-f2 (int x)
-{
-  int a;	/* { dg-warning "set but not used" } */
-  int b;
-  int c;	/* { dg-warning "set but not used" } */
-  c = (a = x, b = x);
-}
-
 int
-f3 (int x)
-{
-  int a;
-  return a = x;
-}
-
-int
-f4 (int x)
-{
-  int a;
-  a = x;
-  return a;
-}
-
-void
-f5 (int x)
-{
-  int a[2];	/* { dg-warning "set but not used" } */
-  int b;
-  int *c, d[2];
-  c = d;
-  b = x;
-  a[b] = 1;
-  c[b] = 1;
-}
-
-int
-f6 (int x)
-{
-  int a[2];
-  int b;
-  b = x;
-  a[b] = 1;
-  return a[b];
-}
-
-void
-f7 (int x, int *p)
-{
-  int *a[2];
-  a[x] = p;
-  a[x][x] = x;
-}
-
-struct S { int i; };
-
-void
-f8 (void)
-{
-  struct S s;	/* { dg-warning "set but not used" } */
-  s.i = 6;
-}
-
-int
-f9 (void)
-{
-  struct S s;
-  s.i = 6;
-  return s.i;
-}
-
-struct S
-f10 (void)
-{
-  struct S s;
-  s.i = 6;
-  return s;
-}
-
-extern int foo11 (int *);
-
-void
-f11 (void)
-{
-  int a[2];
-  foo11 (a);
-}
-
-void
-f12 (void)
+f1 (void)
 {
   int a;
+  int foo (void)
+  {
+    return a;
+  }
   a = 1;
-  a;	/* { dg-warning "statement with no effect" } */
+  return foo ();
 }
 
 void
-f13 (void (*x) (void))
-{
-  void (*a) (void);
-  a = x;
-  a ();
-}
-
-void
-f14 (void (*x) (void))
-{
-  void (*a) (void);	/* { dg-warning "set but not used" } */
-  a = x;
-}
-
-extern void foo15 (int *);
-
-void
-f15 (void)
-{
-  int a[10];
-  int *b = a + 2;
-  foo15 (b);
-}
-
-extern void foo16 (int **);
-
-void
-f16 (void)
-{
-  int a[10];
-  int *b[] = { a, a + 2 };
-  foo16 (b);
-}
-
-void
-f17 (int x)
-{
-  long a;	/* { dg-warning "set but not used" } */
-  int b;
-  a = b = x;
-}
-
-void
-f18 (int x)
+f2 (void)
 {
   int a;	/* { dg-warning "set but not used" } */
-  int b;
-  a = (char) (b = x);
-}
-
-int
-f19 (int x, int y, int z)
-{
-  int a;
-  int b;
-  a = x;
-  b = y;
-  return z ? a : b;
-}
-
-int *
-f20 (int x)
-{
-  static int a[] = { 3, 4, 5, 6 };
-  static int b[] = { 4, 5, 6, 7 };
-  static int c[] = { 5, 6, 7, 8 };	/* { dg-warning "set but not used" } */
-  c[1] = 1;
-  return x ? a : b;
+  void foo (void)
+  {
+    a = 2;
+  }
+  a = 1;
+  foo ();
 }
--- gcc/testsuite/gcc.dg/Wunused-var-4.c.jj	2010-04-07 22:31:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-4.c	2010-04-08 16:24:27.000000000 +0200
@@ -1,26 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-Wunused" } */
-
-int
-f1 (void)
-{
-  int a;
-  int foo (void)
-  {
-    return a;
-  }
-  a = 1;
-  return foo ();
-}
-
-void
-f2 (void)
-{
-  int a;	/* { dg-warning "set but not used" } */
-  void foo (void)
-  {
-    a = 2;
-  }
-  a = 1;
-  foo ();
-}
--- gcc/testsuite/c-c++-common/Wunused-var-2.c.jj	2010-04-08 16:23:28.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-2.c	2010-04-07 22:31:42.000000000 +0200
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+int
+f1 (void)
+{
+  int c = ({
+    int a;
+    a = 1;
+    a; });
+  return c;
+}
+
+void
+f2 (void)
+{
+  int f;
+  f = 0;
+  __asm__ __volatile__ ("" : "+r" (f));
+}
--- gcc/testsuite/c-c++-common/Wunused-var-3.c.jj	2010-04-08 16:23:28.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-3.c	2010-04-07 22:31:42.000000000 +0200
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+void
+f1 (void)
+{
+  _Complex int a;	/* { dg-warning "set but not used" } */
+  _Complex double b;	/* { dg-warning "set but not used" } */
+  __real__ a = 1;
+  __imag__ a = 2;
+  __real__ b = 3.0;
+  __imag__ b = 4.0;
+}
+
+int
+f2 (void)
+{
+  _Complex int a;
+  _Complex double b;
+  __real__ a = 1;
+  __imag__ a = 2;
+  __real__ b = 3.0;
+  __imag__ b = 4.0;
+  return __real__ a + __imag__ b;
+}
+
+_Complex double
+f3 (void)
+{
+  _Complex int a;
+  _Complex double b;
+  __real__ a = 1;
+  __imag__ a = 2;
+  __real__ b = 3.0;
+  __imag__ b = 4.0;
+  return a + b;
+}
--- gcc/testsuite/c-c++-common/Wunused-var-5.c.jj	2010-04-08 16:23:28.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-5.c	2010-04-07 22:31:42.000000000 +0200
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+void
+f1 (void)
+{
+  extern int extvari;
+  extvari = 1;
+}
+
+int extvarj;
+
+void
+f2 (void)
+{
+  extern int extvarj;
+  extvarj = 1;
+}
+
+static int extvark;
+
+void
+f3 (void)
+{
+  extern int extvark;
+  extvark = 1;
+}
+
+int
+f4 (void)
+{
+  return extvark;
+}
--- gcc/testsuite/c-c++-common/Wunused-var-1.c.jj	2010-04-08 16:23:20.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-1.c	2010-04-08 16:31:24.000000000 +0200
@@ -0,0 +1,179 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+void
+f1 (void)
+{
+  int a;	/* { dg-warning "set but not used" } */
+  int b;
+  int c;
+  c = 1;
+  a = b = c;
+}
+
+void
+f2 (int x)
+{
+  int a;	/* { dg-warning "set but not used" } */
+  int b;
+  int c;	/* { dg-warning "set but not used" } */
+  c = (a = x, b = x);
+}
+
+int
+f3 (int x)
+{
+  int a;
+  return a = x;
+}
+
+int
+f4 (int x)
+{
+  int a;
+  a = x;
+  return a;
+}
+
+void
+f5 (int x)
+{
+  int a[2];	/* { dg-warning "set but not used" } */
+  int b;
+  int *c, d[2];
+  c = d;
+  b = x;
+  a[b] = 1;
+  c[b] = 1;
+}
+
+int
+f6 (int x)
+{
+  int a[2];
+  int b;
+  b = x;
+  a[b] = 1;
+  return a[b];
+}
+
+void
+f7 (int x, int *p)
+{
+  int *a[2];
+  a[x] = p;
+  a[x][x] = x;
+}
+
+struct S { int i; };
+
+void
+f8 (void)
+{
+  struct S s;	/* { dg-warning "set but not used" } */
+  s.i = 6;
+}
+
+int
+f9 (void)
+{
+  struct S s;
+  s.i = 6;
+  return s.i;
+}
+
+struct S
+f10 (void)
+{
+  struct S s;
+  s.i = 6;
+  return s;
+}
+
+extern int foo11 (int *);
+
+void
+f11 (void)
+{
+  int a[2];
+  foo11 (a);
+}
+
+void
+f12 (void)
+{
+  int a;
+  a = 1;
+  a;	/* { dg-warning "no effect" } */
+}
+
+void
+f13 (void (*x) (void))
+{
+  void (*a) (void);
+  a = x;
+  a ();
+}
+
+void
+f14 (void (*x) (void))
+{
+  void (*a) (void);	/* { dg-warning "set but not used" } */
+  a = x;
+}
+
+extern void foo15 (int *);
+
+void
+f15 (void)
+{
+  int a[10];
+  int *b = a + 2;
+  foo15 (b);
+}
+
+extern void foo16 (int **);
+
+void
+f16 (void)
+{
+  int a[10];
+  int *b[] = { a, a + 2 };
+  foo16 (b);
+}
+
+void
+f17 (int x)
+{
+  long a;	/* { dg-warning "set but not used" } */
+  int b;
+  a = b = x;
+}
+
+void
+f18 (int x)
+{
+  int a;	/* { dg-warning "set but not used" } */
+  int b;
+  a = (char) (b = x);
+}
+
+int
+f19 (int x, int y, int z)
+{
+  int a;
+  int b;
+  a = x;
+  b = y;
+  return z ? a : b;
+}
+
+int *
+f20 (int x)
+{
+  static int a[] = { 3, 4, 5, 6 };
+  static int b[] = { 4, 5, 6, 7 };
+  static int c[] = { 5, 6, 7, 8 };	/* { dg-warning "set but not used" } */
+  c[1] = 1;
+  return x ? a : b;
+}
--- gcc/testsuite/c-c++-common/Wunused-var-4.c.jj	2010-04-08 16:23:28.000000000 +0200
+++ gcc/testsuite/c-c++-common/Wunused-var-4.c	2010-04-08 16:31:45.000000000 +0200
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused -W" } */
+
+int
+f1 (unsigned int x)
+{
+  int c = ({ union { unsigned int a; int b; } u; u.a = x; u.b; });
+  return c;
+}
+
+void
+f2 (void)
+{
+  struct S { int i; } a;
+  int b[1];
+  a.i = 1;
+  a.i;				/* { dg-warning "no effect" } */
+  b[0] = 1;
+  b[0];				/* { dg-warning "no effect" } */
+}
+
+void
+f3 (void)
+{
+  struct S { int i; } a;	/* { dg-warning "set but not used" } */
+  int b[1];			/* { dg-warning "set but not used" } */
+  a.i = 1;
+  b[0] = 1;
+}
--- gcc/testsuite/g++.dg/template/sfinae16.C.jj	2010-01-22 17:23:43.000000000 +0100
+++ gcc/testsuite/g++.dg/template/sfinae16.C	2010-04-08 16:15:09.000000000 +0200
@@ -29,6 +29,6 @@ template<typename Rep>
 int main()
 {
   duration<int> d0;
-  duration<int> d1 = d0;
+  duration<int> d1 = d0;	// { dg-warning "set but not used" }
 }
 
--- gcc/testsuite/g++.dg/warn/Wunused-var-7.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-7.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,48 @@
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+template <int N>
+void
+f1 (void)
+{
+  _Complex int a;	// { dg-warning "set but not used" }
+  _Complex double b;	// { dg-warning "set but not used" }
+  __real__ a = 1;
+  __imag__ a = 2;
+  __real__ b = 3.0;
+  __imag__ b = 4.0;
+}
+
+template <int N>
+int
+f2 (void)
+{
+  _Complex int a;
+  _Complex double b;
+  __real__ a = 1;
+  __imag__ a = 2;
+  __real__ b = 3.0;
+  __imag__ b = 4.0;
+  return __real__ a + __imag__ b;
+}
+
+template <int N>
+_Complex double
+f3 (void)
+{
+  _Complex int a;
+  _Complex double b;
+  __real__ a = 1;
+  __imag__ a = 2;
+  __real__ b = 3.0;
+  __imag__ b = 4.0;
+  return a + b;
+}
+
+void
+test ()
+{
+  f1<0> ();
+  (void) f2<0> ();
+  (void) f3<0> ();
+}
--- gcc/testsuite/g++.dg/warn/Wunused-var-8.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-8.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,46 @@
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+template <int N>
+void
+f1 (void)
+{
+  extern int extvari;
+  extvari = 1;
+}
+
+int extvarj;
+
+template <int N>
+void
+f2 (void)
+{
+  extern int extvarj;
+  extvarj = 1;
+}
+
+static int extvark;
+
+template <int N>
+void
+f3 (void)
+{
+  extern int extvark;
+  extvark = 1;
+}
+
+template <int N>
+int
+f4 (void)
+{
+  return extvark;
+}
+
+void
+test ()
+{
+  f1<0> ();
+  f2<0> ();
+  f3<0> ();
+  (void) f4<0> ();
+}
--- gcc/testsuite/g++.dg/warn/Wunused-var-3.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-3.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,110 @@
+// { dg-options "-Wunused -W" }
+
+#include <typeinfo>
+#include <stdarg.h>
+
+void
+f1 (int a, ...)
+{
+  va_list ap;
+  va_start (ap, a);
+  va_end (ap);
+}
+
+int
+f2 (int a, ...)
+{
+  va_list ap;
+  va_start (ap, a);
+  int i = va_arg (ap, int);
+  va_end (ap);
+  return i;
+}
+
+struct A { int a; A (); virtual ~A (); };
+struct B : virtual A { int b; };
+
+struct B *
+f3 (struct A *a)
+{
+  return dynamic_cast <B *> (a);
+}
+
+struct A *
+f4 (struct B *a)
+{
+  return static_cast <A *> (a);
+}
+
+struct A *
+f5 (struct B *a)
+{
+  return reinterpret_cast <A *> (a);
+}
+
+struct A *
+f6 (const struct A *a)
+{
+  return const_cast <A *> (a);
+}
+
+int
+f7 (long a)
+{
+  return (int) a;
+}
+
+int
+f8 (long a)
+{
+  return int (a);
+}
+
+struct C
+{
+  operator unsigned int() { return 42; }
+};
+
+unsigned int
+f9 ()
+{
+  C u;
+  return u;
+}
+
+struct D
+{
+  operator int & ();
+  operator const int & () const;
+};
+
+void foo (int &);
+void foo (const int &);
+
+void
+f10 ()
+{
+  const D x = D ();
+  foo (x);
+}
+
+int
+f11 (int a)
+{
+  return typeid (a) == typeid (int);
+}
+
+struct E
+{
+  int e () {return 0;}
+};
+
+template <typename T>
+int
+f12 (E a)
+{
+  __decltype (a.e()) i;
+  return i;
+}
+
+template <> int f12<int> (E);
--- gcc/testsuite/g++.dg/warn/Wunused-parm-3.C.jj	2010-04-08 16:15:09.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-parm-3.C	2010-04-08 16:15:09.000000000 +0200
@@ -0,0 +1,69 @@
+// { dg-do compile }
+// { dg-options "-Wunused -W" }
+
+#include <stdarg.h>
+
+struct A
+{
+  long a;
+  A () : a (0) { }
+  A (long x) : a (x) { }
+  operator long () const { return a; }
+  long operator- (const A& x) const { return a - x.a; }
+};
+
+long
+fn1 (A a)
+{
+  return a - A (0);
+}
+
+struct B
+{
+  bool operator() (const int x, const int y) const throw() { return x < y; }
+};
+
+template <typename T>
+bool 
+fn2 (int x, int y, T z)
+{
+  return z (x, y);
+}
+
+bool
+fn3 (void)
+{
+  return fn2 (1, 2, B ());
+}
+
+int
+fn4 (va_list ap)
+{
+  return va_arg (ap, int);
+}
+
+template <typename T>
+T
+fn5 (va_list ap)
+{
+  return va_arg (ap, T);
+}
+
+int
+fn6 (va_list ap)
+{
+  return fn5 <int> (ap);
+}
+
+template <typename T>
+int
+fn7 (T ap)
+{
+  return va_arg (ap, int);
+}
+
+int
+fn8 (va_list ap)
+{
+  return fn7 (ap);
+}
--- gcc/testsuite/g++.dg/warn/Wunused-parm-2.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-parm-2.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,54 @@
+// { dg-do compile }
+// { dg-options "-Wunused -W" }
+
+template <int N>
+long
+f1 (unsigned long long x)
+{
+  unsigned long long a = 1;
+  const union { unsigned long long l; unsigned int p[2]; } b = { x };
+  const union { unsigned long long l; unsigned int p[2]; } c = { a };
+  return b.p[0] + c.p[0];
+}
+
+template <int N>
+int
+f2 (int x, int y)
+{
+  int a = 1;
+  int b[] = { 1, 2, x, a, 3, 4 };
+  return b[y];
+}
+
+template <int N>
+int
+f3 (int a)	// { dg-warning "unused parameter" }
+{
+  return 0;
+}
+
+template <int N>
+int
+f4 (int a)	// { dg-warning "set but not used" }
+{
+  a = 1;
+  return 0;
+}
+
+template <int N>
+int
+f5 (int a)
+{
+  a = 1;
+  return a;
+}
+
+void
+test ()
+{
+  (void) f1<0> (0);
+  (void) f2<0> (0, 0);
+  (void) f3<0> (0);
+  (void) f4<0> (0);
+  (void) f5<0> (0);
+}
--- gcc/testsuite/g++.dg/warn/Wunused-var-6.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-6.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,29 @@
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+template <int N>
+int
+f1 (void)
+{
+  int c = ({
+    int a;
+    a = 1;
+    a; });
+  return c;
+}
+
+template <int N>
+void
+f2 (void)
+{
+  int f;
+  f = 0;
+  __asm__ __volatile__ ("" : "+r" (f));
+}
+
+void
+test ()
+{
+  (void) f1<0> ();
+  f2<0> ();
+}
--- gcc/testsuite/g++.dg/warn/Wunused-var-1.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-1.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,8 @@
+// { dg-options "-Wunused" }
+template <int> struct X { static const int s = 2; };
+template <typename T> int f() { const int v = 2; return X<v+1>::s; }
+template <typename T> int g() { const int v = 2; return X<v>::s; }
+template <typename T> int h() { const int v = 2; return X<1 ? v : 0>::s; }
+template int f<int>();
+template int g<int>();
+template int h<int>();
--- gcc/testsuite/g++.dg/warn/Wunused-7.C.jj	2010-01-22 17:23:43.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/Wunused-7.C	2010-04-08 16:15:08.000000000 +0200
@@ -6,7 +6,7 @@ void func()
   struct mybitfields {
     unsigned int s_field:8;
   };
-  struct mybitfields s;
+  struct mybitfields s;	// { dg-warning "set but not used" }
   s.s_field = 255;
 };
 
--- gcc/testsuite/g++.dg/warn/Wunused-var-4.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-4.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,50 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+struct S { int e; };
+
+int
+f1 (void)
+{
+  int a;
+  int b;
+  int c;
+  int d;
+  S s;
+  a = 1;
+  b = 2;
+  c = 3;
+  d = 4;
+  s.e = 5;
+  __typeof (c) e;	// { dg-warning "set but not used" }
+  __decltype (d) f;	// { dg-warning "set but not used" }
+  __decltype (s.e) g;	// { dg-warning "set but not used" }
+  e = 1;
+  f = 1;
+  g = 1;
+  return sizeof (a) + __alignof__ (b);
+}
+
+template <int N>
+int f2 (void)
+{
+  int a;
+  int b;
+  int c;
+  int d;
+  a = 1;
+  b = 2;
+  c = 3;
+  d = 4;
+  __typeof (c) e;	// { dg-warning "set but not used" }
+  __decltype (d) f;	// { dg-warning "set but not used" }
+  e = 1;
+  f = 1;
+  return sizeof (a) + __alignof__ (b);
+}
+
+void
+test (void)
+{
+  (void) f2<0> ();
+}
--- gcc/testsuite/g++.dg/warn/Wunused-parm-1.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-parm-1.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,58 @@
+// { dg-do compile }
+// { dg-options "-Wunused -W" }
+
+long
+f1 (unsigned long long x)
+{
+  unsigned long long a = 1;
+  const union { unsigned long long l; unsigned int p[2]; } b = { x };
+  const union { unsigned long long l; unsigned int p[2]; } c = { a };
+  return b.p[0] + c.p[0];
+}
+
+int
+f2 (int x, int y)
+{
+  int a = 1;
+  int b[] = { 1, 2, x, a, 3, 4 };
+  return b[y];
+}
+
+int
+f3 (int a)	// { dg-warning "unused parameter" }
+{
+  return 0;
+}
+
+int
+f4 (int a)	// { dg-warning "set but not used" }
+{
+  a = 1;
+  return 0;
+}
+
+int
+f5 (int a)
+{
+  a = 1;
+  return a;
+}
+
+int
+f6 (int &a)
+{
+  return a;
+}
+
+void
+f7 (int &a)
+{
+  a = 1;
+}
+
+struct S
+{
+  S (int i) : j(i) {}
+  S (long i) : j(i + 1) {}
+  int j;
+};
--- gcc/testsuite/g++.dg/warn/Wunused-var-2.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-2.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,104 @@
+// { dg-options "-Wunused -W" }
+
+extern void foo ();
+
+void
+f1 ()
+{
+  try
+    {
+      foo ();
+    }
+  catch (int i)
+    {
+    }
+  catch (double d)
+    {
+    }
+}
+
+void
+f2 (int x)
+{
+  int a = 0;
+  x++;
+  ++a;
+}
+
+struct A
+{
+  bool foo () const { return true; }
+};
+
+int
+f3 ()
+{
+  A a;
+  bool b = a.foo ();
+  return b;
+}
+
+struct B
+{
+  int i;
+  B (int j);
+};
+
+void
+f4 ()
+{
+  B b (6);
+}
+
+struct C
+{
+  int i;
+  C (int j) : i (j) {}
+};
+
+void
+f5 ()
+{
+  C c (6);
+}
+
+struct D
+{
+  int i;
+  D (int j) : i (j) {}
+  ~D ();
+};
+
+void
+f6 ()
+{
+  D d (6);
+}
+
+int *f7 (int s)
+{
+  return new int[s];
+}
+
+template <typename T>
+T *f8 (int s)
+{
+  return new T[s];
+}
+
+template int *f8<int> (int);
+
+void
+f9 (char *p)
+{
+  delete p;
+}
+
+template <typename T>
+void
+f10 (T *p)
+{
+  delete p;
+}
+
+template void f10<char> (char *);
--- gcc/testsuite/g++.dg/warn/Wunused-var-5.C.jj	2010-04-08 16:15:08.000000000 +0200
+++ gcc/testsuite/g++.dg/warn/Wunused-var-5.C	2010-04-08 16:15:08.000000000 +0200
@@ -0,0 +1,227 @@
+// { dg-do compile }
+// { dg-options "-Wunused" }
+
+template <int N>
+void
+f1 (void)
+{
+  int a;	// { dg-warning "set but not used" }
+  int b;
+  int c;
+  c = 1;
+  a = b = c;
+}
+
+template <int N>
+void
+f2 (int x)
+{
+  int a;	// { dg-warning "set but not used" }
+  int b;
+  int c;	// { dg-warning "set but not used" }
+  c = (a = x, b = x);
+}
+
+template <int N>
+int
+f3 (int x)
+{
+  int a;
+  return a = x;
+}
+
+template <int N>
+int
+f4 (int x)
+{
+  int a;
+  a = x;
+  return a;
+}
+
+template <int N>
+void
+f5 (int x)
+{
+  int a[2];	// { dg-warning "set but not used" }
+  int b;
+  int *c, d[2];
+  c = d;
+  b = x;
+  a[b] = 1;
+  c[b] = 1;
+}
+
+template <int N>
+int
+f6 (int x)
+{
+  int a[2];
+  int b;
+  b = x;
+  a[b] = 1;
+  return a[b];
+}
+
+template <int N>
+void
+f7 (int x, int *p)
+{
+  int *a[2];
+  a[x] = p;
+  a[x][x] = x;
+}
+
+struct S { int i; };
+
+template <int N>
+void
+f8 (void)
+{
+  struct S s;	// { dg-warning "set but not used" }
+  s.i = 6;
+}
+
+template <int N>
+int
+f9 (void)
+{
+  struct S s;
+  s.i = 6;
+  return s.i;
+}
+
+template <int N>
+struct S
+f10 (void)
+{
+  struct S s;
+  s.i = 6;
+  return s;
+}
+
+extern int foo11 (int *);
+
+template <int N>
+void
+f11 (void)
+{
+  int a[2];
+  foo11 (a);
+}
+
+template <int N>
+void
+f12 (void)
+{
+  int a;
+  a = 1;
+  a;	// { dg-warning "statement has no effect" }
+}
+
+template <int N>
+void
+f13 (void (*x) (void))
+{
+  void (*a) (void);
+  a = x;
+  a ();
+}
+
+template <int N>
+void
+f14 (void (*x) (void))
+{
+  void (*a) (void);	// { dg-warning "set but not used" }
+  a = x;
+}
+
+extern void foo15 (int *);
+
+template <int N>
+void
+f15 (void)
+{
+  int a[10];
+  int *b = a + 2;
+  foo15 (b);
+}
+
+extern void foo16 (int **);
+
+template <int N>
+void
+f16 (void)
+{
+  int a[10];
+  int *b[] = { a, a + 2 };
+  foo16 (b);
+}
+
+template <int N>
+void
+f17 (int x)
+{
+  long a;	// { dg-warning "set but not used" }
+  int b;
+  a = b = x;
+}
+
+template <int N>
+void
+f18 (int x)
+{
+  int a;	// { dg-warning "set but not used" }
+  int b;
+  a = (char) (b = x);
+}
+
+template <int N>
+int
+f19 (int x, int y, int z)
+{
+  int a;
+  int b;
+  a = x;
+  b = y;
+  return z ? a : b;
+}
+
+template <int N>
+int *
+f20 (int x)
+{
+  static int a[] = { 3, 4, 5, 6 };
+  static int b[] = { 4, 5, 6, 7 };
+  static int c[] = { 5, 6, 7, 8 };	// { dg-warning "set but not used" }
+  c[1] = 1;
+  return x ? a : b;
+}
+
+S s;
+
+void
+test ()
+{
+  int i = 0;
+  f1<0> ();
+  f2<0> (0);
+  (void) f3<0> (0);
+  (void) f4<0> (0);
+  f5<0> (0);
+  (void) f6<0> (0);
+  f7<0> (0, &i);
+  f8<0> ();
+  (void) f9<0> ();
+  s = f10<0> ();
+  f11<0> ();
+  f12<0> ();
+  f13<0> (f1<0>);
+  f14<0> (f1<0>);
+  f15<0> ();
+  f16<0> ();
+  f17<0> (0);
+  f18<0> (0);
+  (void) f19<0> (0, 0, 0);
+  (void) f20<0> (0);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]