handling TOKEN_CHARCONST - -Wmultibyte-character
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 25 Nov 2012 21:11:21 +0000 (22:11 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 25 Nov 2012 21:11:21 +0000 (22:11 +0100)
lexer.c
main.c
opts.def
parser.c

diff --git a/lexer.c b/lexer.c
index 065f60c2dc129cac8a4da4d9ff5ae3ff5eb54e79..6bd47b065eb3f96220c65417e98fab3c4fa7beb2 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -1290,6 +1290,14 @@ int lex_do(lex_file *lex)
         {
              lex->tok.ttype = TOKEN_VECTORCONST;
         }
+        else
+        {
+            if (!lex->flags.preprocessing && strlen(lex->tok.value) > 1) {
+                if (lexwarn(lex, WARN_MULTIBYTE_CHARACTER, "multibyte character: `%s`", lex->tok.value))
+                    return (lex->tok.ttype = TOKEN_ERROR);
+            }
+            lex->tok.constval.i = lex->tok.value[0];
+        }
 
         return lex->tok.ttype;
     }
diff --git a/main.c b/main.c
index d35e33f83d5c80f27ce47dcd9eedb7ad33df4438..6ee7d8e4611968eb843023d3c6ac8ace965fc64b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -473,6 +473,8 @@ int main(int argc, char **argv) {
     options_set(opts_warn, WARN_PREPROCESSOR, true);
     options_set(opts_warn, WARN_MULTIFILE_IF, true);
     options_set(opts_warn, WARN_DOUBLE_DECLARATION, true);
+    options_set(opts_warn, WARN_CONST_VAR, true);
+    options_set(opts_warn, WARN_MULTIBYTE_CHARACTER, true);
 
     options_set(opts_flags, ADJUST_VECTOR_FIELDS, true);
     options_set(opts_flags, FTEPP, false);
index c083c2b20e17956d6c8de0eb082c29fb6249a382..7f4c15e6d15f3f4d8386c523b55a0515ad0da9b7 100644 (file)
--- a/opts.def
+++ b/opts.def
@@ -62,6 +62,7 @@
     GMQCC_DEFINE_FLAG(MULTIFILE_IF)
     GMQCC_DEFINE_FLAG(DOUBLE_DECLARATION)
     GMQCC_DEFINE_FLAG(CONST_VAR)
+    GMQCC_DEFINE_FLAG(MULTIBYTE_CHARACTER)
 #endif
 
 /* some cleanup so we don't have to */
index e7e205d26d6f9c26ec4bc8ce32a945b2d450c5e8..c840ae6e3f08bb1ea24826a1bcb31a98bf9fe60e 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1428,7 +1428,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
             DEBUGSHUNTDO(con_out("push %g\n", parser_token(parser)->constval.f));
         }
-        else if (parser->tok == TOKEN_INTCONST) {
+        else if (parser->tok == TOKEN_INTCONST || parser->tok == TOKEN_CHARCONST) {
             ast_value *val;
             if (wantop) {
                 parseerror(parser, "expected operator or end of statement, got constant");