Implement (and document \o/) -Werror-implicit-function-declaration.
[cparser] / warning.c
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #include <stdio.h>
21 #include <string.h>
22 #include "warning.h"
23
24 warning_t warning = {
25         .other                               = true,
26
27         .address                             = true,
28         .aggregate_return                    = false,
29         .attribute                           = true,
30         .cast_qual                           = false,
31         .char_subscripts                     = true,
32         .comment                             = false,
33         .conversion                          = false,
34         .declaration_after_statement         = false,
35         .deprecated_declarations             = true,
36         .div_by_zero                         = true,
37         .empty_statement                     = false,
38         .error_implicit_function_declaration = false,
39         .fatal_errors                        = false,
40         .float_equal                         = false,
41         .format                              = true,
42         .implicit_function_declaration       = true,
43         .implicit_int                        = true,
44         .init_self                           = true,
45         .long_long                           = false,
46         .main                                = true,
47         .missing_declarations                = false,
48         .missing_noreturn                    = false,
49         .missing_prototypes                  = false,
50         .multichar                           = true,
51         .nested_externs                      = false,
52         .nonnull                             = true,
53         .old_style_definition                = false,
54         .packed                              = false,
55         .padded                              = false,
56         .pointer_arith                       = true,
57         .redundant_decls                     = true,
58         .return_type                         = true,
59         .s_are_errors                        = false,
60         .shadow                              = false,
61         .sign_compare                        = false,
62         .strict_prototypes                   = true,
63         .switch_default                      = false,
64         .switch_enum                         = false,
65         .traditional                         = false,
66         .unknown_pragmas                     = true,
67         .unreachable_code                    = false,
68         .unused_function                     = false,
69         .unused_label                        = false,
70         .unused_parameter                    = false,
71         .unused_value                        = true,
72         .unused_variable                     = false,
73         .write_strings                       = false
74 };
75
76 void set_warning_opt(const char *const opt)
77 {
78         const char* s = opt;
79
80         bool state = true;
81
82         /* "no-" prefix */
83         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
84                 s += 3;
85                 state = false;
86         }
87
88         if (0) {}
89 #define OPTX(x)   else if (strcmp(s, x) == 0)
90 #define SET(y)    (void)(warning.y = state)
91 #define OPT(x, y) OPTX(x) SET(y)
92         OPTX("all") {
93                 /* Note: this switched on a lot more warnings than gcc's -Wall */
94                 SET(other);
95
96                 SET(address);
97                 SET(attribute);
98                 SET(char_subscripts);
99                 SET(comment);
100                 SET(empty_statement);
101                 SET(format);
102                 SET(implicit_function_declaration);
103                 SET(implicit_int);
104                 SET(init_self);
105                 SET(main);
106                 SET(nonnull);
107                 SET(pointer_arith);
108                 SET(redundant_decls);
109                 SET(return_type);
110                 SET(shadow);
111                 SET(sign_compare);
112                 SET(strict_prototypes);
113                 SET(switch_enum);
114                 SET(unknown_pragmas);
115                 SET(unreachable_code);
116                 SET(unused_function);
117                 SET(unused_label);
118                 SET(unused_parameter);
119                 SET(unused_value);
120                 SET(unused_variable);
121         }
122         OPT("address",                             address);
123         OPT("aggregate-return",                    aggregate_return);
124         OPT("attribute",                           attribute);
125         OPT("cast-qual",                           cast_qual);
126         OPT("char-subscripts",                     char_subscripts);
127         OPT("comment",                             comment);
128         OPT("conversion",                          conversion);
129         OPT("declaration-after-statement",         declaration_after_statement);
130         OPT("deprecated-declarations",             deprecated_declarations);
131         OPT("div-by-zero",                         div_by_zero);
132         OPT("empty-statement",                     empty_statement);
133         OPT("error",                               s_are_errors);
134         OPT("error-implicit-function-declaration", error_implicit_function_declaration);
135         OPTX("extra") {
136                 /* TODO */
137                 // TODO SET(function_end_without_return);
138                 SET(empty_statement);
139                 // TODO SET(incomplete_aggregate_init);
140                 // TODO SET(missing_field_initializers);
141                 // TODO SET(pointless_comparison);
142                 SET(unused_parameter);
143                 SET(unused_value);
144         }
145         OPT("fatal-errors",                        fatal_errors);
146         OPT("float-equal",                         float_equal);
147         OPTX("format") {
148                 SET(format);
149                 SET(nonnull);
150         }
151         OPTX("implicit") {
152                 SET(implicit_function_declaration);
153                 SET(implicit_int);
154         }
155         OPT("implicit-function-declaration",       implicit_function_declaration);
156         OPT("implicit-int",                        implicit_int);
157         OPT("init-self",                           init_self);
158         OPT("long-long",                           long_long);
159         OPT("main",                                main);
160         OPT("missing-declarations",                missing_declarations);
161         OPT("missing-noreturn",                    missing_noreturn);
162         OPT("missing-prototypes",                  missing_prototypes);
163         OPT("multichar",                           multichar);
164         OPT("nested-externs",                      nested_externs);
165         OPT("nonnull",                             nonnull);
166         OPT("old-style-definition",                old_style_definition);
167         OPT("packed",                              packed);
168         OPT("padded",                              padded);
169         OPT("pointer-arith",                       pointer_arith);
170         OPT("redundant-decls",                     redundant_decls);
171         OPT("return-type",                         return_type);
172         OPT("shadow",                              shadow);
173         OPT("sign-compare",                        sign_compare);
174         OPT("strict-prototypes",                   strict_prototypes);
175         OPT("switch-default",                      switch_default);
176         OPT("switch-enum",                         switch_enum);
177         OPT("traditional",                         traditional);
178         OPT("unknown-pragmas",                     unknown_pragmas);
179         OPT("unreachable-code",                    unreachable_code);
180         OPTX("unused") {
181                 SET(unused_function);
182                 SET(unused_label);
183                 SET(unused_parameter);
184                 SET(unused_value);
185                 SET(unused_variable);
186         }
187         OPT("unused-function",                     unused_function);
188         OPT("unused-label",                        unused_label);
189         OPT("unused-parameter",                    unused_parameter);
190         OPT("unused-value",                        unused_value);
191         OPT("unused-variable",                     unused_variable);
192         OPT("write-strings",                       write_strings);
193 #undef OPT
194 #undef SET
195 #undef OPT_X
196         else {
197                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
198         }
199 }