diff options
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index e21c566..0cbccae 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -227,6 +227,7 @@ static int opt_comp PARAMS ((const void *, const void *)); #endif static int parse_option PARAMS ((const char *)); static int handle_option PARAMS ((cpp_reader *, int, char **)); +static int report_missing_guard PARAMS ((splay_tree_node, void *)); /* Fourth argument to append_include_chain: chain to use */ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; @@ -1003,6 +1004,27 @@ cpp_start_read (pfile, print, fname) return 1; } +static int +report_missing_guard (n, b) + splay_tree_node n; + void *b; +{ + struct include_file *f = (struct include_file *) n->value; + int *bannerp = (int *)b; + + if (f && f->cmacro == 0 && f->include_count == 1) + { + if (*bannerp == 0) + { + fputs (_("Multiple include guards may be useful for:\n"), stderr); + *bannerp = 1; + } + fputs (f->name, stderr); + putc ('\n', stderr); + } + return 0; +} + /* This is called at the end of preprocessing. It pops the last buffer and writes dependency output. It should also clear macro definitions, such that you could call cpp_start_read @@ -1055,6 +1077,14 @@ cpp_finish (pfile, print) if (ferror (print->outf) || fclose (print->outf)) cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); } + + /* Report on headers that could use multiple include guards. */ + if (CPP_OPTION (pfile, print_include_names)) + { + int banner = 0; + splay_tree_foreach (pfile->all_include_files, report_missing_guard, + (void *) &banner); + } } static void |