Implement -Wmissing_prototypes.
authorChristoph Mallon <christoph.mallon@gmx.de>
Thu, 13 Dec 2007 22:04:01 +0000 (22:04 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 13 Dec 2007 22:04:01 +0000 (22:04 +0000)
[r18733]

parser.c
warning.c
warning.h

index efccdcd..0c49e62 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2297,7 +2297,12 @@ static declaration_t *internal_record_declaration(
                                                        old_storage_class = STORAGE_CLASS_EXTERN;
 
                                                case STORAGE_CLASS_EXTERN:
-                                                       if (new_storage_class == STORAGE_CLASS_NONE && !is_function_definition) {
+                                                       if (is_function_definition) {
+                                                               if (warning.missing_prototypes &&
+                                                                   prev_type->function.unspecified_parameters) {
+                                                                       warningf(declaration->source_position, "no previous prototype for '%#T'", type, symbol);
+                                                               }
+                                                       } else if (new_storage_class == STORAGE_CLASS_NONE) {
                                                                new_storage_class = STORAGE_CLASS_EXTERN;
                                                        }
                                                        break;
@@ -2308,7 +2313,7 @@ static declaration_t *internal_record_declaration(
 
                                if (old_storage_class == STORAGE_CLASS_EXTERN &&
                                                new_storage_class == STORAGE_CLASS_EXTERN) {
-       warn_redundant_declaration:
+warn_redundant_declaration:
                                        if (warning.redundant_decls) {
                                                warningf(declaration->source_position, "redundant declaration for '%Y'", symbol);
                                                warningf(previous_declaration->source_position, "previous declaration of '%Y' was here", symbol);
@@ -2338,9 +2343,12 @@ static declaration_t *internal_record_declaration(
                        return previous_declaration;
                }
        } else if (is_function_definition &&
-                       declaration->storage_class != STORAGE_CLASS_STATIC &&
-                       warning.missing_declarations) {
-               warningf(declaration->source_position, "no previous declaration for '%#T'", type, symbol);
+                       declaration->storage_class != STORAGE_CLASS_STATIC) {
+               if (warning.missing_prototypes) {
+                       warningf(declaration->source_position, "no previous prototype for '%#T'", type, symbol);
+               } else if (warning.missing_declarations) {
+                       warningf(declaration->source_position, "no previous declaration for '%#T'", type, symbol);
+               }
        }
 
        assert(declaration->parent_context == NULL);
index d914ae9..7a718cd 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -28,6 +28,7 @@ void set_warning_opt(const char *const opt)
        OPT("implicit-function-declaration", implicit_function_declaration)
        OPT("implicit-int",                  implicit_int)
        OPT("missing-declarations",          missing_declarations)
+       OPT("missing-prototypes",            missing_prototypes)
        OPT("redundant-decls",               redundant_decls)
        OPT("strict-prototypes",             strict_prototypes)
 #if 0
@@ -54,6 +55,7 @@ warning_t warning = {
        .implicit_function_declaration = true,
        .implicit_int                  = true,
        .missing_declarations          = true,
+       .missing_prototypes            = true,
        .strict_prototypes             = true,
        .redundant_decls               = true,
        .unused_value                  = true
index df36717..ab2acef 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -37,7 +37,9 @@ typedef struct warning_t {
 #if 0 // TODO
        bool missing_format_attribute:1;      /* If '-Wformat' is enabled, also warn about functions which might be candidates for 'format' attributes */
        bool missing_noreturn:1;              /* Warn about functions which might be candidates for attribute 'noreturn' */
+#endif
        bool missing_prototypes:1;            /* Warn if a global function is defined without a previous prototype declaration */
+#if 0 // TODO
        bool multichar:1;                     /* Warn if a multicharacter constant ('FOOF') is used. */
        bool nested_externs:1;                /* Warn if an 'extern' declaration is encountered within a function */
        bool packed:1;                        /* Warn if a structure is given the packed attribute, but the packed attribute has no effect on the layout or size of the structure */