From 718d6a577cf109bc76988187e4d948e0c3bc1954 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sat, 15 Dec 2007 04:14:15 +0000 Subject: [PATCH] finished -Wunused-function [r18765] --- parser.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/parser.c b/parser.c index fd50903..b949dda 100644 --- a/parser.c +++ b/parser.c @@ -5713,6 +5713,33 @@ static void initialize_builtin_types(void) type_wchar_t_ptr = make_pointer_type(type_wchar_t, TYPE_QUALIFIER_NONE); } +/** + * Check for unused functions in the given scope. + */ +static void check_unused_functions(const scope_t *scope) { + bool first_err = true; + const declaration_t *declaration = scope->declarations; + + for (; declaration != NULL; declaration = declaration->next) { + if (! declaration->used) { + if (declaration->storage_class == STORAGE_CLASS_STATIC) { + const type_t *type = declaration->type; + + if (is_type_function(type)) { + if (first_err) { + first_err = false; + diagnosticf("%s: At top level:\n", + declaration->source_position.input_name); + } + warningf(declaration->source_position, + "'%Y' defined but not used", + declaration->symbol); + } + } + } + } +} + /** * Parse a translation unit. */ @@ -5743,6 +5770,9 @@ static translation_unit_t *parse_translation_unit(void) last_declaration = NULL; assert(global_scope == &unit->scope); + if (warning.unused_function) { + check_unused_functions(global_scope); + } global_scope = NULL; return unit; -- 2.20.1