Implement -Wswitch-default.
[cparser] / warning.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "warning.h"
4
5 void set_warning_opt(const char *const opt)
6 {
7         const char* s = opt;
8
9         bool state = true;
10         /* no- modifier */
11         if (s[0] == 'n' && s[1] == 'o' && s[2] == '-') {
12                 s += 3;
13                 state = false;
14         }
15
16         if (0) {}
17 #define OPTX(x)   else if (strcmp(s, x) == 0)
18 #define SET(y)    warning.y = state;
19 #define OPT(x, y) OPTX(x) SET(y)
20         OPT("char-subscripts",               char_subscripts)
21         OPT("error",                         s_are_errors)
22         OPT("fatal-errors",                  fatal_errors)
23         OPT("format",                        check_format)
24         OPTX("implicit") {
25                 SET(implicit_function_declaration)
26                 SET(implicit_int)
27         }
28         OPT("implicit-function-declaration", implicit_function_declaration)
29         OPT("implicit-int",                  implicit_int)
30         OPT("missing-declarations",          missing_declarations)
31         OPT("missing-prototypes",            missing_prototypes)
32         OPT("redundant-decls",               redundant_decls)
33         OPT("strict-prototypes",             strict_prototypes)
34         OPT("switch-default",                switch_default)
35 #if 0
36         OPTX("unused") {
37                 SET(unused_function)
38                 SET(unused_label)
39                 SET(unused_parameter)
40                 SET(unused_variable)
41                 SET(unused_value)
42         }
43 #endif
44         OPT("unused-value",                  unused_value)
45 #undef OPT
46 #undef SET
47 #undef OPT_X
48         else {
49                 fprintf(stderr, "warning: ignoring unknown option -W%s\n", opt);
50         }
51 }
52
53 warning_t warning = {
54         .char_subscripts               = true,
55         .check_format                  = true,
56         .fatal_errors                  = false,
57         .implicit_function_declaration = true,
58         .implicit_int                  = true,
59         .missing_declarations          = true,
60         .missing_prototypes            = true,
61         .redundant_decls               = true,
62         .s_are_errors                  = false,
63         .strict_prototypes             = true,
64         .switch_default                = false,
65         .unused_value                  = true
66 };