-Werror implemented
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 11 Dec 2007 21:30:48 +0000 (21:30 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 11 Dec 2007 21:30:48 +0000 (21:30 +0000)
[r18682]

diagnostic.c
diagnostic.h
main.c

index fab118e..9af6491 100644 (file)
@@ -7,7 +7,6 @@
 #include "token_t.h"
 #include "type.h"
 
-
 //#define ABORT_ON_ERROR
 
 /** Number of occurred diagnostics. */
@@ -16,6 +15,8 @@ unsigned diagnostic_count = 0;
 unsigned error_count      = 0;
 /** Number of occurred warnings. */
 unsigned warning_count    = 0;
+/* true if warnings should be treated as errors */
+bool warnings_are_errors  = false;
 
 /**
  * Issue a diagnostic message.
@@ -138,10 +139,10 @@ void diagnosticf(const char *const fmt, ...)
 
 void errorf(const source_position_t pos, const char *const fmt, ...)
 {
-       ++error_count;
-       fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr);
        va_list ap;
        va_start(ap, fmt);
+       fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr);
+       ++error_count;
        diagnosticvf(fmt, ap);
        va_end(ap);
        fputc('\n', stderr);
@@ -153,10 +154,15 @@ void errorf(const source_position_t pos, const char *const fmt, ...)
 
 void warningf(const source_position_t pos, const char *const fmt, ...)
 {
-       ++warning_count;
-       fprintf(stderr, "%s:%u: warning: ", pos.input_name, pos.linenr);
        va_list ap;
        va_start(ap, fmt);
+       if (warnings_are_errors) {
+               fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr);
+               ++error_count;
+       } else {
+               fprintf(stderr, "%s:%u: warning: ", pos.input_name, pos.linenr);
+               ++warning_count;
+       }
        diagnosticvf(fmt, ap);
        va_end(ap);
        fputc('\n', stderr);
index 06f9220..27a1821 100644 (file)
@@ -11,4 +11,7 @@ extern unsigned diagnostic_count;
 extern unsigned error_count;
 extern unsigned warning_count;
 
+/* true if warnings should be treated as errors */
+extern bool warnings_are_errors;
+
 #endif
diff --git a/main.c b/main.c
index df18c2e..abf0fbf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -451,6 +451,14 @@ int main(int argc, char **argv)
                        } else if (res == -1) {
                                help_displayed = true;
                        }
+               } else if(arg[0] == '-' && arg[1] == 'W') {
+                       const char *opt;
+                       GET_ARG_AFTER(opt, "-W");
+                       if (strcmp(opt, "error") == 0) {
+                               warnings_are_errors = true;
+                       } else {
+                               fprintf(stderr, "warning: ignoring gcc option -W%s\n", opt);
+                       }
                } else if(arg[0] == '-' && arg[1] == 'm') {
                        const char *opt;
                        GET_ARG_AFTER(opt, "-m");
@@ -477,7 +485,6 @@ int main(int argc, char **argv)
                        } else if(strcmp(arg, "-pedantic") == 0) {
                                fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
                        } else if(arg[1] == 'O' ||
-                                       arg[1] == 'W' ||
                                        arg[1] == 'g' ||
                                        strncmp(arg + 1, "std=", 4) == 0) {
                                fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);