-BugFix: must use const_wchar_T
[cparser] / parser.c
index f9920b8..5961692 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5512,7 +5512,7 @@ static expression_t *parse_string_const(void)
                        /* note: that we use type_char_ptr here, which is already the
                         * automatic converted type. revert_automatic_type_conversion
                         * will construct the array type */
-                       cnst->base.type    = type_char_ptr;
+                       cnst->base.type    = warning.write_strings ? type_const_char_ptr : type_char_ptr;
                        cnst->string.value = res;
                        return cnst;
                }
@@ -5535,7 +5535,7 @@ static expression_t *parse_string_const(void)
 
                        default: {
                                expression_t *const cnst = allocate_expression_zero(EXPR_WIDE_STRING_LITERAL);
-                               cnst->base.type         = type_wchar_t_ptr;
+                               cnst->base.type         = warning.write_strings ? type_const_wchar_t_ptr : type_wchar_t_ptr;
                                cnst->wide_string.value = wres;
                                return cnst;
                        }
@@ -6998,18 +6998,29 @@ static bool check_pointer_arithmetic(const source_position_t *source_position,
        points_to = skip_typeref(points_to);
 
        if (is_type_incomplete(points_to) &&
-                       (! (c_mode & _GNUC)
-                        || !is_type_atomic(points_to, ATOMIC_TYPE_VOID))) {
+                       !((c_mode & _GNUC)
+                        && is_type_atomic(points_to, ATOMIC_TYPE_VOID))) {
                errorf(source_position,
-                          "arithmetic with pointer to incomplete type '%T' not allowed",
-                          orig_pointer_type);
+                      "arithmetic with pointer to incomplete type '%T' not allowed",
+                      orig_pointer_type);
                return false;
-       } else if (is_type_function(points_to)) {
+       } else if (!(c_mode & _GNUC) && is_type_function(points_to)) {
                errorf(source_position,
-                          "arithmetic with pointer to function type '%T' not allowed",
-                          orig_pointer_type);
+                      "arithmetic with pointer to function type '%T' not allowed",
+                      orig_pointer_type);
                return false;
        }
+       if (warning.pointer_arith) {
+               if (is_type_atomic(points_to, ATOMIC_TYPE_VOID)) {
+                       warningf(source_position,
+                                "pointer of type '%T' used in arithmetic",
+                                orig_pointer_type);
+               } else if (is_type_function(points_to)) {
+                       warningf(source_position,
+                                "pointer to a function '%T' used in arithmetic",
+                                orig_pointer_type);
+               }
+       }
        return true;
 }
 
@@ -9163,6 +9174,13 @@ static void initialize_builtin_types(void)
        type_ptrdiff_t_ptr = make_pointer_type(type_ptrdiff_t, TYPE_QUALIFIER_NONE);
        type_ssize_t_ptr   = make_pointer_type(type_ssize_t,   TYPE_QUALIFIER_NONE);
        type_wchar_t_ptr   = make_pointer_type(type_wchar_t,   TYPE_QUALIFIER_NONE);
+
+       /* const version of wchar_t */
+       type_const_wchar_t = allocate_type_zero(TYPE_TYPEDEF, &builtin_source_position);
+       type_const_wchar_t->typedeft.declaration = type_wchar_t->typedeft.declaration;
+       type_const_wchar_t->base.modifiers |= TYPE_QUALIFIER_CONST;
+
+       type_const_wchar_t_ptr = make_pointer_type(type_const_wchar_t, TYPE_QUALIFIER_NONE);
 }
 
 /**