/* 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;
}
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_char_ptr : type_wchar_t_ptr;
cnst->wide_string.value = wres;
return cnst;
}
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);
}
/**
type_t *type_error_type;
type_t *type_char;
+type_t *type_const_char;
type_t *type_double;
type_t *type_float;
type_t *type_int;
type_t *type_void;
type_t *type_char_ptr;
+type_t *type_const_char_ptr;
type_t *type_int_ptr;
type_t *type_long_long_ptr;
type_t *type_long_ptr;
type_t *type_uintmax_t;
type_t *type_uptrdiff_t;
type_t *type_wchar_t;
+type_t *type_const_wchar_t;
type_t *type_wint_t;
type_t *type_intmax_t_ptr;
type_t *type_ptrdiff_t_ptr;
type_t *type_ssize_t_ptr;
type_t *type_wchar_t_ptr;
+type_t *type_const_wchar_t_ptr;
/* microsoft types */
atomic_type_kind_t int8_type_kind = ATOMIC_TYPE_INVALID;
type_long_long_ptr = make_pointer_type(type_long_long, TYPE_QUALIFIER_NONE);
type_char_ptr_ptr = make_pointer_type(type_char_ptr, TYPE_QUALIFIER_NONE);
+
+ /* const character types */
+ type_const_char = make_atomic_type(ATOMIC_TYPE_CHAR, TYPE_QUALIFIER_CONST);
+ type_const_char_ptr = make_pointer_type(type_const_char, TYPE_QUALIFIER_NONE);
}
extern type_t *type_error_type;
extern type_t *type_char;
+extern type_t *type_const_char;
extern type_t *type_double;
extern type_t *type_float;
extern type_t *type_int;
extern type_t *type_void;
extern type_t *type_char_ptr;
+extern type_t *type_const_char_ptr;
extern type_t *type_int_ptr;
extern type_t *type_long_long_ptr;
extern type_t *type_long_ptr;
extern type_t *type_uintmax_t;
extern type_t *type_uptrdiff_t;
extern type_t *type_wchar_t;
+extern type_t *type_const_wchar_t;
extern type_t *type_wchar_ptr_t;
extern type_t *type_wint_t;
extern type_t *type_ptrdiff_t_ptr;
extern type_t *type_ssize_t_ptr;
extern type_t *type_wchar_t_ptr;
+extern type_t *type_const_wchar_t_ptr;
/* microsoft types */
extern atomic_type_kind_t int8_type_kind;
.unused_label = false,
.unused_parameter = false,
.unused_value = true,
- .unused_variable = false
+ .unused_variable = false,
+ .write_strings = false
};
void set_warning_opt(const char *const opt)
OPT("unused-parameter", unused_parameter);
OPT("unused-value", unused_value);
OPT("unused-variable", unused_variable);
+ OPT("write-strings", write_strings);
#undef OPT
#undef SET
#undef OPT_X
bool unused_parameter:1; /**< Warn whenever a function parameter is unused aside from its declaration */
bool unused_value:1; /**< Warn whenever a statement computes a result that is explicitly not used */
bool unused_variable:1; /**< Warn whenever a local variable or non-constant static variable is unused aside from its declaration */
-#if 0 // TODO
bool write_strings:1; /**< Give string constants the type 'const char[LENGTH]' so that copying the address of one into a 'char *' pointer will get a warning */
-#endif
} warning_t;
extern warning_t warning;