PATCH: Fix PR c/13029

Mark Mitchell mark@codesourcery.com
Thu Nov 13 19:42:00 GMT 2003


I applied this patch, which had gone on to the 3.3 branch but which
Kean did not apply to the mainline.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-11-13  Mark Mitchell  <mark@codesourcery.com>
            Kean Johnston <jkj@sco.com>

	PR c/13029
	* toplev.c (check_global_declarations): Do not warn about unused
	static consts.

2003-11-13  Mark Mitchell  <mark@codesourcery.com>
            Kean Johnston <jkj@sco.com>

	PR c/13029
	* gcc.dg/unused-4.c: Update.

Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.843
diff -c -5 -p -r1.843 toplev.c
*** toplev.c	1 Nov 2003 02:23:44 -0000	1.843
--- toplev.c	13 Nov 2003 19:35:50 -0000
*************** check_global_declarations (tree *vec, in
*** 1718,1728 ****
  	  assemble_external (decl);
  	}
  
        /* Warn about static fns or vars defined but not used.  */
        if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
! 	   || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
  	  && ! TREE_USED (decl)
  	  /* The TREE_USED bit for file-scope decls is kept in the identifier,
  	     to handle multiple external decls in different scopes.  */
  	  && ! TREE_USED (DECL_NAME (decl))
  	  && ! DECL_EXTERNAL (decl)
--- 1718,1732 ----
  	  assemble_external (decl);
  	}
  
        /* Warn about static fns or vars defined but not used.  */
        if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
! 	   /* We don't warn about "static const" variables because the
! 	      "rcs_id" idiom uses that construction.  */
! 	   || (warn_unused_variable
! 	       && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
! 	  && ! DECL_IN_SYSTEM_HEADER (decl)
  	  && ! TREE_USED (decl)
  	  /* The TREE_USED bit for file-scope decls is kept in the identifier,
  	     to handle multiple external decls in different scopes.  */
  	  && ! TREE_USED (DECL_NAME (decl))
  	  && ! DECL_EXTERNAL (decl)
Index: testsuite/gcc.dg/unused-4.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/unused-4.c,v
retrieving revision 1.1
diff -c -5 -p -r1.1 unused-4.c
*** testsuite/gcc.dg/unused-4.c	3 Apr 2002 22:39:51 -0000	1.1
--- testsuite/gcc.dg/unused-4.c	13 Nov 2003 19:35:55 -0000
***************
*** 1,6 ****
  /* { dg-do compile } */
  /* { dg-options "-Wunused -O3" } */
  
! static const int i = 0;		/* { dg-warning "defined but not used" } */
  static void f() { }		/* { dg-warning "defined but not used" } */
  static inline void g() { }
--- 1,6 ----
  /* { dg-do compile } */
  /* { dg-options "-Wunused -O3" } */
  
! static const int i = 0;
  static void f() { }		/* { dg-warning "defined but not used" } */
  static inline void g() { }



More information about the Gcc-patches mailing list