summaryrefslogtreecommitdiff
path: root/gcc/cppinit.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2002-07-23 22:57:49 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2002-07-23 22:57:49 +0000
commit71a7c28254983fb0228469f2b602347a4717dfec (patch)
treed7305615fe0d53e288982b583d2c9c637deb2699 /gcc/cppinit.c
parent44a8c9661982dea2fa5a0b8b22d96d67bdde8cc8 (diff)
downloadgcc-71a7c28254983fb0228469f2b602347a4717dfec.tar.gz
* cppexp.c (parse_defined): Mark macro used.
* cpphash.h (struct cpp_macro): New member "used". (_cpp_mark_macro_used, _cpp_warn_if_unused_macro): New. (struct cpp_reader): New member. * cppinit.c (cpp_finish_options): Set first_unused_line. (cpp_finish): Warn of unused macros if requested. (OPT_TABLE): New switches. (cpp_handle_option): Handle them. * cpplib.c (do_undef): Warn if macro unused. (do_ifdef, do_ifndef): Mark macro used. * cpplib.h (struct cpp_options): New member. * cppmacro.c (_cpp_warn_if_unused_macro): New. (enter_macro_context): Mark macro used. (_cpp_create_definition): Mark macro unused; warn if unused when redefined. * cpptrad.c (scan_out_logcial_line, push_replacement_text): Mark macros used. * doc/cppopts.texi: Update. testsuite: * gcc.dg/cpp/trad/Wunused.c, gcc.dg/cpp/trad/Wunused.h, gcc.dg/cpp/Wunused.c, gcc.dg/cpp/Wunused.h: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55692 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r--gcc/cppinit.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index a6be4aa6736..6a4dd0a53f8 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -1009,6 +1009,8 @@ cpp_finish_options (pfile)
_cpp_maybe_push_include_file (pfile);
}
+ pfile->first_unused_line = pfile->line;
+
free_chain (CPP_OPTION (pfile, pending)->imacros_head);
free_chain (CPP_OPTION (pfile, pending)->directive_head);
}
@@ -1081,6 +1083,10 @@ void
cpp_finish (pfile)
cpp_reader *pfile;
{
+ /* Warn about unused macros before popping the final buffer. */
+ if (CPP_OPTION (pfile, warn_unused_macros))
+ cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL);
+
/* cpplex.c leaves the final buffer on the stack. This it so that
it returns an unending stream of CPP_EOFs to the client. If we
popped the buffer, we'd dereference a NULL buffer pointer and
@@ -1165,10 +1171,12 @@ new_pending_directive (pend, text, handler)
DEF_OPT("Wno-traditional", 0, OPT_Wno_traditional) \
DEF_OPT("Wno-trigraphs", 0, OPT_Wno_trigraphs) \
DEF_OPT("Wno-undef", 0, OPT_Wno_undef) \
+ DEF_OPT("Wno-unused-macros", 0, OPT_Wno_unused_macros) \
DEF_OPT("Wsystem-headers", 0, OPT_Wsystem_headers) \
DEF_OPT("Wtraditional", 0, OPT_Wtraditional) \
DEF_OPT("Wtrigraphs", 0, OPT_Wtrigraphs) \
DEF_OPT("Wundef", 0, OPT_Wundef) \
+ DEF_OPT("Wunused-macros", 0, OPT_Wunused_macros) \
DEF_OPT("d", no_arg, OPT_d) \
DEF_OPT("fno-operator-names", 0, OPT_fno_operator_names) \
DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
@@ -1692,6 +1700,13 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, warn_comments) = 0;
break;
+ case OPT_Wunused_macros:
+ CPP_OPTION (pfile, warn_unused_macros) = 1;
+ break;
+ case OPT_Wno_unused_macros:
+ CPP_OPTION (pfile, warn_unused_macros) = 0;
+ break;
+
case OPT_Wundef:
CPP_OPTION (pfile, warn_undef) = 1;
break;