View | Details | Raw Unified | Return to bug 33255 | Differences between
and this patch

Collapse All | Expand All | Context: (Patch / File /
)

(-)a/gcc/Makefile.in (-1 / +1 lines)
 Lines 937-943   ALIAS_H = alias.h coretypes.h Link Here 
937
EMIT_RTL_H = emit-rtl.h
937
EMIT_RTL_H = emit-rtl.h
938
FLAGS_H = flags.h coretypes.h flag-types.h $(OPTIONS_H)
938
FLAGS_H = flags.h coretypes.h flag-types.h $(OPTIONS_H)
939
OPTIONS_H = options.h flag-types.h $(OPTIONS_H_EXTRA)
939
OPTIONS_H = options.h flag-types.h $(OPTIONS_H_EXTRA)
940
FUNCTION_H = function.h $(TREE_H) $(HASHTAB_H) vecprim.h $(TM_H) hard-reg-set.h
940
FUNCTION_H = function.h $(TREE_H) $(HASHTAB_H) vecprim.h $(TM_H) hard-reg-set.h pointer-set.h
941
EXPR_H = expr.h insn-config.h $(FUNCTION_H) $(RTL_H) $(FLAGS_H) $(TREE_H) $(MACHMODE_H) $(EMIT_RTL_H)
941
EXPR_H = expr.h insn-config.h $(FUNCTION_H) $(RTL_H) $(FLAGS_H) $(TREE_H) $(MACHMODE_H) $(EMIT_RTL_H)
942
OPTABS_H = optabs.h insn-codes.h
942
OPTABS_H = optabs.h insn-codes.h
943
REGS_H = regs.h $(MACHMODE_H) hard-reg-set.h
943
REGS_H = regs.h $(MACHMODE_H) hard-reg-set.h
(-)a/gcc/c-family/c-common.c (+88 lines)
 Lines 9576-9581   record_types_used_by_current_var_decl (tree decl) Link Here 
9576
    }
9576
    }
9577
}
9577
}
9578
9578
9579
/* If DECL is a typedef that is declared in the current function,
9580
   record it in CFUN->LOCAL_TYPEDEFS.   */
9581
9582
void
9583
record_locally_defined_typedef (tree decl)
9584
{
9585
  if (!is_typedef_decl (decl))
9586
    return;
9587
9588
  if (!DECL_CONTEXT (decl)
9589
      || DECL_CONTEXT (decl) != current_function_decl)
9590
    return;
9591
9592
  VEC_safe_push (tree, gc, cfun->local_typedefs, decl);
9593
}
9594
9595
/* If T is a typedef variant type or a TYPE_DECL declared locally,
9596
   record it in CFUN->USED_LOCAL_TYPEDEFS.  Note that this function
9597
   does not record the typedefs presents in the subtypes of T.  */
9598
9599
void
9600
maybe_record_local_typedef_use (tree t)
9601
{
9602
  tree typedef_decl = NULL_TREE;
9603
9604
  /* We want T to be either a type or a TYPE_DECL.   */
9605
  if (t == NULL_TREE
9606
      || (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL))
9607
    return;
9608
9609
  if (TYPE_P (t))
9610
    {
9611
      if (typedef_variant_p (t))
9612
	typedef_decl = TYPE_NAME (t);
9613
    }
9614
  else
9615
    {
9616
      if (is_typedef_decl (t))
9617
	typedef_decl = t;
9618
    }
9619
9620
  if (typedef_decl != NULL_TREE)
9621
    {
9622
      /* We are only interested in a typedef declared locally.  */
9623
      if (DECL_CONTEXT (typedef_decl) != current_function_decl)
9624
	return;
9625
9626
      /* If this typedef is local, really record its use now.  */
9627
      if (cfun->used_local_typedefs == NULL)
9628
	cfun->used_local_typedefs = pointer_set_create ();
9629
      pointer_set_insert (cfun->used_local_typedefs, typedef_decl);
9630
    }
9631
}
9632
9633
/* Warn if there are some unused locally defined typedefs in the
9634
   current function. */
9635
9636
void
9637
maybe_warn_unused_local_typedefs (void)
9638
{
9639
  int i;
9640
  tree decl;
9641
9642
  if (cfun->used_local_typedefs != NULL)
9643
    gcc_assert (cfun->local_typedefs != NULL);
9644
9645
  if (warn_unused_local_typedefs)
9646
    {
9647
      FOR_EACH_VEC_ELT (tree, cfun->local_typedefs, i, decl)
9648
	if (cfun->used_local_typedefs == NULL
9649
	    || !pointer_set_contains (cfun->used_local_typedefs, decl))
9650
	  warning_at (DECL_SOURCE_LOCATION (decl),
9651
		      OPT_Wunused_local_typedefs,
9652
		      "typedef %qD locally defined but not used", decl);
9653
    }
9654
9655
  if (cfun->used_local_typedefs)
9656
    {
9657
      pointer_set_destroy (cfun->used_local_typedefs);
9658
      cfun->used_local_typedefs = NULL;
9659
    }
9660
  if (cfun->local_typedefs)
9661
    {
9662
      VEC_free (tree, gc, cfun->local_typedefs);
9663
      cfun->local_typedefs = NULL;
9664
    }
9665
}
9666
9579
/* The C and C++ parsers both use vectors to hold function arguments.
9667
/* The C and C++ parsers both use vectors to hold function arguments.
9580
   For efficiency, we keep a cache of unused vectors.  This is the
9668
   For efficiency, we keep a cache of unused vectors.  This is the
9581
   cache.  */
9669
   cache.  */
(-)a/gcc/c-family/c-common.h (-1 / +4 lines)
 Lines 960-966   extern void warn_for_sign_compare (location_t, Link Here 
960
				   enum tree_code resultcode);
960
				   enum tree_code resultcode);
961
extern void do_warn_double_promotion (tree, tree, tree, const char *, 
961
extern void do_warn_double_promotion (tree, tree, tree, const char *, 
962
				      location_t);
962
				      location_t);
963
extern void set_underlying_type (tree x);
963
extern void set_underlying_type (tree);
964
extern void record_locally_defined_typedef (tree);
965
extern void maybe_record_local_typedef_use (tree);
966
extern void maybe_warn_unused_local_typedefs (void);
964
extern VEC(tree,gc) *make_tree_vector (void);
967
extern VEC(tree,gc) *make_tree_vector (void);
965
extern void release_tree_vector (VEC(tree,gc) *);
968
extern void release_tree_vector (VEC(tree,gc) *);
966
extern VEC(tree,gc) *make_tree_vector_single (tree);
969
extern VEC(tree,gc) *make_tree_vector_single (tree);
(-)a/gcc/c-family/c.opt (+4 lines)
 Lines 649-654   Wunsuffixed-float-constants Link Here 
649
C ObjC Var(warn_unsuffixed_float_constants) Warning
649
C ObjC Var(warn_unsuffixed_float_constants) Warning
650
Warn about unsuffixed float constants
650
Warn about unsuffixed float constants
651
651
652
Wunused-local-typedefs
653
C++ Var(warn_unused_local_typedefs) Warning Init(-1)
654
Warn about
655
652
Wunused-macros
656
Wunused-macros
653
C ObjC C++ ObjC++ Warning
657
C ObjC C++ ObjC++ Warning
654
Warn about macros defined in the main file that are not used
658
Warn about macros defined in the main file that are not used
(-)a/gcc/cp/cp-tree.h (-1 / +2 lines)
 Lines 4953-4959   extern bool defer_mark_used_calls; Link Here 
4953
extern GTY(()) VEC(tree, gc) *deferred_mark_used_calls;
4953
extern GTY(()) VEC(tree, gc) *deferred_mark_used_calls;
4954
extern tree finish_case_label			(location_t, tree, tree);
4954
extern tree finish_case_label			(location_t, tree, tree);
4955
extern tree cxx_maybe_build_cleanup		(tree, tsubst_flags_t);
4955
extern tree cxx_maybe_build_cleanup		(tree, tsubst_flags_t);
4956
4956
void cp_maybe_record_local_typedef_use          (tree);
4957
void cp_used_types_insert                       (tree);
4957
/* in decl2.c */
4958
/* in decl2.c */
4958
extern bool check_java_method			(tree);
4959
extern bool check_java_method			(tree);
4959
extern tree build_memfn_type			(tree, tree, cp_cv_quals);
4960
extern tree build_memfn_type			(tree, tree, cp_cv_quals);
(-)a/gcc/cp/decl.c (+6 lines)
 Lines 10312-10317   grokdeclarator (const cp_declarator *declarator, Link Here 
10312
    if (!processing_template_decl)
10312
    if (!processing_template_decl)
10313
      cp_apply_type_quals_to_decl (type_quals, decl);
10313
      cp_apply_type_quals_to_decl (type_quals, decl);
10314
10314
10315
    cp_maybe_record_local_typedef_use (TREE_TYPE (decl));
10316
10315
    return decl;
10317
    return decl;
10316
  }
10318
  }
10317
}
10319
}
 Lines 13372-13377   finish_function (int flags) Link Here 
13372
      unused_but_set_errorcount = errorcount;
13374
      unused_but_set_errorcount = errorcount;
13373
    }
13375
    }
13374
13376
13377
  /* Complain about locally defined typedefs that are not used in this
13378
     function.  */
13379
  maybe_warn_unused_local_typedefs ();
13380
13375
  /* Genericize before inlining.  */
13381
  /* Genericize before inlining.  */
13376
  if (!processing_template_decl)
13382
  if (!processing_template_decl)
13377
    {
13383
    {
(-)a/gcc/cp/decl2.c (+3 lines)
 Lines 4175-4180   mark_used (tree decl) Link Here 
4175
4175
4176
  /* Set TREE_USED for the benefit of -Wunused.  */
4176
  /* Set TREE_USED for the benefit of -Wunused.  */
4177
  TREE_USED (decl) = 1;
4177
  TREE_USED (decl) = 1;
4178
4179
  cp_maybe_record_local_typedef_use (TREE_TYPE (decl));
4180
4178
  if (DECL_CLONED_FUNCTION_P (decl))
4181
  if (DECL_CLONED_FUNCTION_P (decl))
4179
    TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
4182
    TREE_USED (DECL_CLONED_FUNCTION (decl)) = 1;
4180
4183
(-)a/gcc/cp/init.c (+2 lines)
 Lines 2612-2617   build_new (VEC(tree,gc) **placement, tree type, tree nelts, Link Here 
2612
  if (type == error_mark_node)
2612
  if (type == error_mark_node)
2613
    return error_mark_node;
2613
    return error_mark_node;
2614
2614
2615
  cp_maybe_record_local_typedef_use (type);
2616
2615
  if (nelts == NULL_TREE && VEC_length (tree, *init) == 1)
2617
  if (nelts == NULL_TREE && VEC_length (tree, *init) == 1)
2616
    {
2618
    {
2617
      tree auto_node = type_uses_auto (type);
2619
      tree auto_node = type_uses_auto (type);
(-)a/gcc/cp/name-lookup.c (+7 lines)
 Lines 871-876   pushdecl_maybe_friend_1 (tree x, bool is_friend) Link Here 
871
	      && TYPE_NAME (type)
871
	      && TYPE_NAME (type)
872
	      && TYPE_IDENTIFIER (type))
872
	      && TYPE_IDENTIFIER (type))
873
	    set_identifier_type_value (DECL_NAME (x), x);
873
	    set_identifier_type_value (DECL_NAME (x), x);
874
875
	  /* If this is a locally defined typedef in a function that
876
	     is not a template instantation, record it to implement
877
	     -Wunused-local-typedefs.  */
878
	  if (current_instantiation () == NULL
879
	      || (current_instantiation ()->decl != current_function_decl))
880
	  record_locally_defined_typedef (x);
874
	}
881
	}
875
882
876
      /* Multiple external decls of the same identifier ought to match.
883
      /* Multiple external decls of the same identifier ought to match.
(-)a/gcc/cp/parser.c (+7 lines)
 Lines 4649-4654   cp_parser_qualifying_entity (cp_parser *parser, Link Here 
4649
      scope = cp_parser_namespace_name (parser);
4649
      scope = cp_parser_namespace_name (parser);
4650
    }
4650
    }
4651
4651
4652
  cp_maybe_record_local_typedef_use (scope);
4652
  return scope;
4653
  return scope;
4653
}
4654
}
4654
4655
 Lines 11632-11637   cp_parser_template_id (cp_parser *parser, Link Here 
11632
      template_id = lookup_template_function (templ, arguments);
11633
      template_id = lookup_template_function (templ, arguments);
11633
    }
11634
    }
11634
11635
11636
  /* Mark the possible use of a typedefs in the arguments, for the
11637
     purpose of -Wunused-local-typedefs.  */
11638
  if (arguments != NULL_TREE)
11639
    for (i = 0; i < TREE_VEC_LENGTH (arguments); ++i)
11640
      cp_maybe_record_local_typedef_use (TREE_VEC_ELT (arguments, i));
11641
11635
  /* If parsing tentatively, replace the sequence of tokens that makes
11642
  /* If parsing tentatively, replace the sequence of tokens that makes
11636
     up the template-id with a CPP_TEMPLATE_ID token.  That way,
11643
     up the template-id with a CPP_TEMPLATE_ID token.  That way,
11637
     should we re-parse the token stream, we will not have to repeat
11644
     should we re-parse the token stream, we will not have to repeat
(-)a/gcc/cp/rtti.c (-1 / +1 lines)
 Lines 521-527   build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) Link Here 
521
  const char *errstr = NULL;
521
  const char *errstr = NULL;
522
522
523
  /* Save casted types in the function's used types hash table.  */
523
  /* Save casted types in the function's used types hash table.  */
524
  used_types_insert (type);
524
  cp_used_types_insert (type);
525
525
526
  /* T shall be a pointer or reference to a complete class type, or
526
  /* T shall be a pointer or reference to a complete class type, or
527
     `pointer to cv void''.  */
527
     `pointer to cv void''.  */
(-)a/gcc/cp/tree.c (+47 lines)
 Lines 47-52   static tree build_local_temp (tree); Link Here 
47
static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
47
static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *);
48
static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *);
48
static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *);
49
static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
49
static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
50
static tree cp_maybe_record_local_typedef_use_r (tree*, int *, void *);
50
51
51
/* If REF is an lvalue, returns the kind of lvalue that REF is.
52
/* If REF is an lvalue, returns the kind of lvalue that REF is.
52
   Otherwise, returns clk_none.  */
53
   Otherwise, returns clk_none.  */
 Lines 3439-3444   cp_free_lang_data (tree t) Link Here 
3439
    }
3440
    }
3440
}
3441
}
3441
3442
3443
/* Subroutine of cp_maybe_record_local_typedef_use, called from
3444
   cp_walk_tree_without_duplicate.   */
3445
3446
static tree
3447
cp_maybe_record_local_typedef_use_r (tree *tp,
3448
				     int *walk_subtrees ATTRIBUTE_UNUSED,
3449
				     void *data ATTRIBUTE_UNUSED)
3450
{
3451
  maybe_record_local_typedef_use (*tp);
3452
  return NULL_TREE;
3453
}
3454
3455
/* If T is a typedef variant type or a TYPE_DECL declared locally,
3456
   record it in CFUN->USED_LOCAL_TYPEDEFS.  This function also records
3457
   the typedefs that are direct or indirect subtypes of T.  */
3458
3459
void
3460
cp_maybe_record_local_typedef_use (tree t)
3461
{
3462
  if (!warn_unused_local_typedefs)
3463
    return;
3464
3465
  /*  If the current function is being instantiated, bail out.  */
3466
  if (current_instantiation () != NULL
3467
      && (current_instantiation ()->decl == current_function_decl))
3468
    return;
3469
3470
  maybe_record_local_typedef_use (t);
3471
3472
  /* Record the typedefs used by subtypes of TYPE.  */
3473
  cp_walk_tree_without_duplicates (&t,
3474
				   cp_maybe_record_local_typedef_use_r,
3475
				   NULL_TREE);
3476
}
3477
3478
/* Given a type, insert it into the used hash table in cfun.  If that
3479
   type is a typedef, mark it as used for the purpose implementing
3480
   -Wunused-local-typedefs.  */
3481
3482
void
3483
cp_used_types_insert (tree t)
3484
{
3485
  used_types_insert (t);
3486
  cp_maybe_record_local_typedef_use (t);
3487
}
3488
3442
/* Stub for c-common.  Please keep in sync with c-decl.c.
3489
/* Stub for c-common.  Please keep in sync with c-decl.c.
3443
   FIXME: If address space support is target specific, then this
3490
   FIXME: If address space support is target specific, then this
3444
   should be a C target hook.  But currently this is not possible,
3491
   should be a C target hook.  But currently this is not possible,
(-)a/gcc/cp/typeck.c (-3 / +5 lines)
 Lines 1518-1523   cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain) Link Here 
1518
      value = size_one_node;
1518
      value = size_one_node;
1519
    }
1519
    }
1520
1520
1521
  maybe_record_local_typedef_use (type);
1522
1521
  dependent_p = dependent_type_p (type);
1523
  dependent_p = dependent_type_p (type);
1522
  if (!dependent_p)
1524
  if (!dependent_p)
1523
    complete_type (type);
1525
    complete_type (type);
 Lines 5712-5718   build_static_cast_1 (tree type, tree expr, bool c_cast_p, Link Here 
5712
  intype = TREE_TYPE (expr);
5714
  intype = TREE_TYPE (expr);
5713
5715
5714
  /* Save casted types in the function's used types hash table.  */
5716
  /* Save casted types in the function's used types hash table.  */
5715
  used_types_insert (type);
5717
  cp_used_types_insert (type);
5716
5718
5717
  /* [expr.static.cast]
5719
  /* [expr.static.cast]
5718
5720
 Lines 6015-6021   build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, Link Here 
6015
  intype = TREE_TYPE (expr);
6017
  intype = TREE_TYPE (expr);
6016
6018
6017
  /* Save casted types in the function's used types hash table.  */
6019
  /* Save casted types in the function's used types hash table.  */
6018
  used_types_insert (type);
6020
  cp_used_types_insert (type);
6019
6021
6020
  /* [expr.reinterpret.cast]
6022
  /* [expr.reinterpret.cast]
6021
     An lvalue expression of type T1 can be cast to the type
6023
     An lvalue expression of type T1 can be cast to the type
 Lines 6235-6241   build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, Link Here 
6235
    }
6237
    }
6236
6238
6237
  /* Save casted types in the function's used types hash table.  */
6239
  /* Save casted types in the function's used types hash table.  */
6238
  used_types_insert (dst_type);
6240
  cp_used_types_insert (dst_type);
6239
6241
6240
  src_type = TREE_TYPE (expr);
6242
  src_type = TREE_TYPE (expr);
6241
  /* Expressions do not really have reference types.  */
6243
  /* Expressions do not really have reference types.  */
(-)a/gcc/cp/typeck2.c (+2 lines)
 Lines 1607-1612   build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) Link Here 
1607
      type = error_mark_node;
1607
      type = error_mark_node;
1608
    }
1608
    }
1609
1609
1610
  cp_maybe_record_local_typedef_use (type);
1611
1610
  if (processing_template_decl)
1612
  if (processing_template_decl)
1611
    {
1613
    {
1612
      tree t;
1614
      tree t;
(-)a/gcc/doc/invoke.texi (-3 / +9 lines)
 Lines 267-274   Objective-C and Objective-C++ Dialects}. Link Here 
267
-Wsystem-headers  -Wtrampolines  -Wtrigraphs  -Wtype-limits  -Wundef @gol
267
-Wsystem-headers  -Wtrampolines  -Wtrigraphs  -Wtype-limits  -Wundef @gol
268
-Wuninitialized  -Wunknown-pragmas  -Wno-pragmas @gol
268
-Wuninitialized  -Wunknown-pragmas  -Wno-pragmas @gol
269
-Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
269
-Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
270
-Wunused-label  -Wunused-parameter -Wno-unused-result -Wunused-value @gol
270
-Wunused-label  -Wunused-local-typedefs -Wunused-parameter @gol
271
-Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable @gol
271
-Wno-unused-result -Wunused-value @gol -Wunused-variable @gol
272
-Wunused-but-set-parameter -Wunused-but-set-variable @gol
272
-Wvariadic-macros -Wvla -Wvolatile-register-var  -Wwrite-strings}
273
-Wvariadic-macros -Wvla -Wvolatile-register-var  -Wwrite-strings}
273
274
274
@item C and Objective-C-only Warning Options
275
@item C and Objective-C-only Warning Options
 Lines 2554-2559   C++-specific options (e.g., @option{-Wabi}). Link Here 
2554
Here is a list of options that are @emph{only} for compiling Objective-C
2555
Here is a list of options that are @emph{only} for compiling Objective-C
2555
and Objective-C++ programs:
2556
and Objective-C++ programs:
2556
2557
2558
@item -Wunused-local-typedefs @r{(C++ and Objective-C++ only)}
2559
@opindex Wunused-local-typedefs
2560
Warn when a typedef locally defined in a function is not used.
2561
2557
@table @gcctabopt
2562
@table @gcctabopt
2558
@item -fconstant-string-class=@var{class-name}
2563
@item -fconstant-string-class=@var{class-name}
2559
@opindex fconstant-string-class
2564
@opindex fconstant-string-class
 Lines 3019-3026   name is still supported, but the newer name is more descriptive.) Link Here 
3019
-Wsign-compare  @gol
3024
-Wsign-compare  @gol
3020
-Wtype-limits  @gol
3025
-Wtype-limits  @gol
3021
-Wuninitialized  @gol
3026
-Wuninitialized  @gol
3022
-Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)} @gol
3023
-Wunused-but-set-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)}  @gol
3027
-Wunused-but-set-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)}  @gol
3028
-Wunused-local-typedefs @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)}  @gol
3029
-Wunused-parameter @r{(only with} @option{-Wunused} @r{or} @option{-Wall}@r{)} @gol
3024
}
3030
}
3025
3031
3026
The option @option{-Wextra} also prints warning messages for the
3032
The option @option{-Wextra} also prints warning messages for the
(-)a/gcc/function.h (+8 lines)
 Lines 27-32   along with GCC; see the file COPYING3. If not see Link Here 
27
#include "vecprim.h"
27
#include "vecprim.h"
28
#include "tm.h"		/* For CUMULATIVE_ARGS.  */
28
#include "tm.h"		/* For CUMULATIVE_ARGS.  */
29
#include "hard-reg-set.h"
29
#include "hard-reg-set.h"
30
#include "pointer-set.h"
30
31
31
/* Stack of pending (incomplete) sequences saved by `start_sequence'.
32
/* Stack of pending (incomplete) sequences saved by `start_sequence'.
32
   Each element describes one pending sequence.
33
   Each element describes one pending sequence.
 Lines 532-537   struct GTY(()) function { Link Here 
532
  /* Vector of function local variables, functions, types and constants.  */
533
  /* Vector of function local variables, functions, types and constants.  */
533
  VEC(tree,gc) *local_decls;
534
  VEC(tree,gc) *local_decls;
534
535
536
  /* Vector of locally defined typedefs, for
537
     -Wunused-local-typedefs.  */
538
  VEC(tree,gc) *local_typedefs;
539
540
  /*  Set of typedefs that are used in this function.  */
541
  struct pointer_set_t * GTY((skip)) used_local_typedefs;
542
535
  /* For md files.  */
543
  /* For md files.  */
536
544
537
  /* tm.h can use this to store whatever it likes.  */
545
  /* tm.h can use this to store whatever it likes.  */
(-)a/gcc/opts.c (+4 lines)
 Lines 830-835   finish_options (struct gcc_options *opts, struct gcc_options *opts_set, Link Here 
830
  if (opts->x_warn_unused_value == -1)
830
  if (opts->x_warn_unused_value == -1)
831
    opts->x_warn_unused_value = opts->x_warn_unused;
831
    opts->x_warn_unused_value = opts->x_warn_unused;
832
832
833
  if (opts->x_warn_unused_local_typedefs == -1)
834
    opts->x_warn_unused_local_typedefs = (opts->x_warn_unused
835
					  && opts->x_extra_warnings);
836
833
  /* This replaces set_Wextra.  */
837
  /* This replaces set_Wextra.  */
834
  if (opts->x_warn_uninitialized == -1)
838
  if (opts->x_warn_uninitialized == -1)
835
    opts->x_warn_uninitialized = opts->x_extra_warnings;
839
    opts->x_warn_uninitialized = opts->x_extra_warnings;
(-)a/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs.C (+127 lines)
Line 0    Link Here 
1
// Origin PR c++/33255
2
// { dg-options "-Wunused-local-typedefs" }
3
// { dg-do compile }
4
5
void
6
test_warn()
7
{
8
  typedef int foo; // { dg-warning "locally defined but not used" }
9
}
10
11
struct S
12
{
13
    typedef int T;
14
    S() {}
15
    S(int) {}
16
};
17
18
template<class T>
19
struct ST
20
{
21
    typedef T type;
22
    ST (int) {}
23
    ST () {}
24
};
25
26
void
27
test0()
28
{
29
    typedef struct S foo;
30
    foo var __attribute__((unused));
31
}
32
33
void
34
test1()
35
{
36
    typedef struct S foo;
37
    foo v;
38
    const foo &var = v;
39
}
40
41
template<class T>
42
void
43
test2_tmpl(void)
44
{
45
    typedef struct ST<T> foo;
46
    foo(2);
47
}
48
49
int
50
test2(void)
51
{
52
    test2_tmpl<int>();
53
}
54
55
void
56
test3(void)
57
{
58
    typedef int foo;
59
    ST<foo> a;
60
}
61
62
63
int
64
test4(void)
65
{
66
    typedef S foo;
67
    foo::T i = 0;
68
    return i;
69
}
70
71
template<class T>
72
void
73
test5_tmpl(void)
74
{
75
    typedef struct ST<int> foo;
76
    ST<int> v;
77
    const foo &var = v;
78
}
79
80
void
81
test5(void)
82
{
83
    test5_tmpl<int>();
84
}
85
86
void
87
test6(void)
88
{
89
  typedef int foo;
90
  void func(foo);  
91
}
92
93
void
94
test7(void)
95
{
96
  typedef int foo;
97
  int vec[1] = {sizeof (foo)};
98
}
99
100
void
101
test8(void)
102
{
103
  typedef int T0;
104
  typedef char T1;
105
  typedef int* T2;
106
  typedef unsigned T3;
107
  struct C0 { virtual void f(void) {}};
108
  struct C1 : C0 {};
109
  typedef C0 T4;
110
111
  int v0 = (T0) 2;
112
  char v1 = static_cast<T1> (0);
113
  reinterpret_cast<T2> (&v0);
114
  unsigned* const c = 0;
115
  unsigned* v2 = const_cast<T3* const> (c);
116
  C0 *p0 = 0;
117
  C1 *p1 = 0;
118
  p0 = dynamic_cast<T4*> (p1);  
119
}
120
121
void
122
test9(void)
123
{
124
  struct C0 {};
125
  typedef C0 foo;
126
  C0 *v = new foo;
127
}
(-)a/gcc/tree.c (-1 / +5 lines)
 Lines 10325-10330   walk_type_fields (tree type, walk_tree_fn func, void *data, Link Here 
10325
{
10325
{
10326
  tree result = NULL_TREE;
10326
  tree result = NULL_TREE;
10327
10327
10328
  /* If this type is a typedef variant, walk the fields of its
10329
     underlying type.  */
10330
  if (typedef_variant_p (type))
10331
    WALK_SUBTREE (DECL_ORIGINAL_TYPE (TYPE_NAME (type)));
10332
10328
  switch (TREE_CODE (type))
10333
  switch (TREE_CODE (type))
10329
    {
10334
    {
10330
    case POINTER_TYPE:
10335
    case POINTER_TYPE:
10331
- 

Return to bug 33255