From 1474fe46658b9f862fea62b270754bd5a3eb243c Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Wed, 6 Apr 1994 07:31:44 -0400 Subject: [PATCH] (warn_missing_declarations): New variable. (c_decode_option): -Wmissing-declarations. (start_function): Actually do the checking. From-SVN: r6981 --- gcc/c-decl.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 13b51f9d600..53b08ee2253 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -484,6 +484,11 @@ int warn_strict_prototypes; int warn_missing_prototypes; +/* Nonzero means warn for any global function def + without separate previous decl. */ + +int warn_missing_declarations; + /* Nonzero means warn about multiple (redundant) decls for the same single variable or function. */ @@ -627,6 +632,10 @@ c_decode_option (p) warn_missing_prototypes = 1; else if (!strcmp (p, "-Wno-missing-prototypes")) warn_missing_prototypes = 0; + else if (!strcmp (p, "-Wmissing-declarations")) + warn_missing_declarations = 1; + else if (!strcmp (p, "-Wno-missing-declarations")) + warn_missing_declarations = 0; else if (!strcmp (p, "-Wredundant-decls")) warn_redundant_decls = 1; else if (!strcmp (p, "-Wno-redundant-decls")) @@ -5832,7 +5841,20 @@ start_function (declspecs, declarator, nested) else if (warn_missing_prototypes && old_decl != 0 && TREE_USED (old_decl) && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)) - warning_with_decl (decl1, "`%s' was used with no prototype before its definition"); + warning_with_decl (decl1, + "`%s' was used with no prototype before its definition"); + /* Optionally warn of any global def with no previous declaration. */ + else if (warn_missing_declarations + && TREE_PUBLIC (decl1) + && old_decl == 0 + && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1)))) + warning_with_decl (decl1, "no previous declaration for `%s'"); + /* Optionally warn of any def with no previous declaration + if the function has already been used. */ + else if (warn_missing_declarations + && old_decl != 0 && TREE_USED (old_decl)) + warning_with_decl (decl1, + "`%s' was used with no declaration before its definition"); /* This is a definition, not a reference. So normally clear DECL_EXTERNAL. -- 2.30.2