From: Ulya Trofimovich Date: Mon, 27 Jul 2015 20:29:03 +0000 (+0100) Subject: Improved warning messages with '-Werror'. X-Git-Tag: 0.15~173 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64c030b8e5399fbb7850763b03306bbd8a9e7fef;p=re2c Improved warning messages with '-Werror'. Report an error rather than a warning (at least GCC does so). --- diff --git a/re2c/src/conf/msg.cc b/re2c/src/conf/msg.cc index b8a20c69..a69ac459 100644 --- a/re2c/src/conf/msg.cc +++ b/re2c/src/conf/msg.cc @@ -24,16 +24,18 @@ void error_encoding () error ("only one of switches -e, -w, -x, -u and -8 must be set"); } -void warning (const char * type, uint32_t line, const char * fmt, ...) +void warning (const char * type, uint32_t line, bool error, const char * fmt, ...) { - fprintf (stderr, "re2c: warning: line %u: ", line); + static const char * msg = error ? "error" : "warning"; + fprintf (stderr, "re2c: %s: line %u: ", msg, line); va_list args; va_start (args, fmt); vfprintf (stderr, fmt, args); va_end (args); - fprintf (stderr, " [-W%s]\n", type); + const char * prefix = error ? "error-" : ""; + fprintf (stderr, " [-W%s%s]\n", prefix, type); } void usage () diff --git a/re2c/src/conf/msg.h b/re2c/src/conf/msg.h index c3eed608..1034131f 100644 --- a/re2c/src/conf/msg.h +++ b/re2c/src/conf/msg.h @@ -8,7 +8,7 @@ namespace re2c { void error (const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 1, 2))); void error_encoding (); -void warning (const char * type, uint32_t line, const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 3, 4))); +void warning (const char * type, uint32_t line, bool error, const char * fmt, ...) RE2C_GXX_ATTRIBUTE ((format (printf, 4, 5))); void usage (); void vernum (); void version (); diff --git a/re2c/src/conf/warn.cc b/re2c/src/conf/warn.cc index 54b3cce2..f06263be 100644 --- a/re2c/src/conf/warn.cc +++ b/re2c/src/conf/warn.cc @@ -66,11 +66,9 @@ void Warn::empty_class (uint32_t line) { if (mask[EMPTY_CHARACTER_CLASS] & WARNING) { - if (mask[EMPTY_CHARACTER_CLASS] & ERROR) - { - error_accuml = true; - } - warning (names[EMPTY_CHARACTER_CLASS], line, "empty character class"); + const bool e = mask[EMPTY_CHARACTER_CLASS] & ERROR; + error_accuml |= e; + warning (names[EMPTY_CHARACTER_CLASS], line, e, "empty character class"); } } @@ -78,11 +76,9 @@ void Warn::match_empty_string (uint32_t line) { if (mask[MATCH_EMPTY_STRING] & WARNING) { - if (mask[MATCH_EMPTY_STRING] & ERROR) - { - error_accuml = true; - } - warning (names[MATCH_EMPTY_STRING], line, "rule matches empty string"); + const bool e = mask[MATCH_EMPTY_STRING] & ERROR; + error_accuml |= e; + warning (names[MATCH_EMPTY_STRING], line, e, "rule matches empty string"); } } @@ -90,10 +86,8 @@ void Warn::naked_default (uint32_t line, const std::vector