* c-decl.c (c_make_fname_decl): Use it.
* c-lex.c (cb_ident, lex_string): Likewise.
* c-typeck.c (free_all_tagged_tu_seen_up_to): Likewise.
* gcc.c (set_spec, read_specs, for_each_path, execute, do_spec_1,
give_switch, set_multilib_dir): Likewise.
* gengtype-parse.c (string_seq, typedef_name): Likewise.
* passes.c (execute_one_pass): Likewise.
* prefix.c (update_path): Likewise.
* pretty-print.c (pp_base_destroy_prefix): Likewise.
* tree.c (build_string): Likewise.
cp:
* call.c (name_as_c_string): Use CONST_CAST.
* decl.c (build_decl): Likewise.
* parser.c (cp_parser_string_literal): Likewise.
fortran:
* gfortranspec.c (lang_specific_driver): Use CONST_CAST.
* options.c (gfc_post_options): Likewise.
* parse.c (parse_omp_structured_block): Likewise.
* st.c (gfc_free_statement): Likewise.
java:
* jcf-parse.c (read_class, java_parse_file): Use CONST_CAST.
* jcf.h (JCF_FINISH): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127344
138bc75d-0d04-0410-961f-
82ee72b054a4
+2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * system.h (CONST_CAST): New.
+ * c-decl.c (c_make_fname_decl): Use it.
+ * c-lex.c (cb_ident, lex_string): Likewise.
+ * c-typeck.c (free_all_tagged_tu_seen_up_to): Likewise.
+ * gcc.c (set_spec, read_specs, for_each_path, execute, do_spec_1,
+ give_switch, set_multilib_dir): Likewise.
+ * gengtype-parse.c (string_seq, typedef_name): Likewise.
+ * passes.c (execute_one_pass): Likewise.
+ * prefix.c (update_path): Likewise.
+ * pretty-print.c (pp_base_destroy_prefix): Likewise.
+ * tree.c (build_string): Likewise.
+
2007-08-10 Aldy Hernandez <aldyh@redhat.com>
* tree-flow-inline.h (is_exec_stmt): Remove.
DECL_ARTIFICIAL (decl) = 1;
init = build_string (length + 1, name);
- free ((char *) name);
+ free (CONST_CAST (name));
TREE_TYPE (init) = type;
DECL_INITIAL (decl) = init;
if (cpp_interpret_string (pfile, str, 1, &cstr, false))
{
ASM_OUTPUT_IDENT (asm_out_file, (const char *) cstr.text);
- free ((void *) cstr.text);
+ free (CONST_CAST (cstr.text));
}
}
#endif
(parse_in, strs, concats + 1, &istr, wide))
{
value = build_string (istr.len, (const char *) istr.text);
- free ((void *) istr.text);
+ free (CONST_CAST (istr.text));
if (c_lex_string_translate == -1)
{
*valp = build_string (istr.len, (const char *) istr.text);
valp = &TREE_CHAIN (*valp);
}
- free ((void *) istr.text);
+ free (CONST_CAST (istr.text));
}
}
else
const struct tagged_tu_seen_cache *const tu1
= (const struct tagged_tu_seen_cache *) tu;
tu = tu1->next;
- free ((void *)tu1);
+ free (CONST_CAST (tu1));
}
tagged_tu_seen_base = tu_til;
}
+2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * call.c (name_as_c_string): Use CONST_CAST.
+ * decl.c (build_decl): Likewise.
+ * parser.c (cp_parser_string_literal): Likewise.
+
2007-08-10 Paolo Carlini <pcarlini@suse.de>
PR c++/17763
if (IDENTIFIER_CTOR_OR_DTOR_P (name))
{
pretty_name
- = (char *) IDENTIFIER_POINTER (constructor_name (type));
+ = (char *) CONST_CAST (IDENTIFIER_POINTER (constructor_name (type)));
/* For a destructor, add the '~'. */
if (name == complete_dtor_identifier
|| name == base_dtor_identifier
*free_p = true;
}
else
- pretty_name = (char *) IDENTIFIER_POINTER (name);
+ pretty_name = (char *) CONST_CAST (IDENTIFIER_POINTER (name));
return pretty_name;
}
tree decl = build_decl (VAR_DECL, id, type);
if (name)
- free ((char *) name);
+ free (CONST_CAST (name));
/* As we're using pushdecl_with_scope, we must set the context. */
DECL_CONTEXT (decl) = current_function_decl;
if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
(parse_in, strs, count, &istr, wide))
{
- value = build_string (istr.len, (char *)istr.text);
- free ((void *)istr.text);
+ value = build_string (istr.len, (const char *)istr.text);
+ free (CONST_CAST (istr.text));
TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node;
value = fix_string_type (value);
+2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * gfortranspec.c (lang_specific_driver): Use CONST_CAST.
+ * options.c (gfc_post_options): Likewise.
+ * parse.c (parse_omp_structured_block): Likewise.
+ * st.c (gfc_free_statement): Likewise.
+
2007-08-10 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/32933
g77_xargc = argc;
g77_xargv = argv;
g77_newargc = 0;
- g77_newargv = (const char **) argv;
+ g77_newargv = (const char **) CONST_CAST (argv);
/* First pass through arglist.
gfc_add_include_path (".", true);
if (canon_source_file != gfc_source_file)
- gfc_free ((void *) canon_source_file);
+ gfc_free (CONST_CAST (canon_source_file));
/* Decide which form the file will be read in as. */
&& strcmp (cp->ext.omp_name, new_st.ext.omp_name) != 0))
gfc_error ("Name after !$omp critical and !$omp end critical does "
"not match at %C");
- gfc_free ((char *) new_st.ext.omp_name);
+ gfc_free (CONST_CAST (new_st.ext.omp_name));
break;
case EXEC_OMP_END_SINGLE:
cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]
break;
case EXEC_OMP_CRITICAL:
- gfc_free ((char *) p->ext.omp_name);
+ gfc_free (CONST_CAST (p->ext.omp_name));
break;
case EXEC_OMP_FLUSH:
/* Free the old spec. */
if (old_spec && sl->alloc_p)
- free ((void *) old_spec);
+ free (CONST_CAST(old_spec));
sl->alloc_p = 1;
}
set_spec (p2, *(sl->ptr_spec));
if (sl->alloc_p)
- free ((void *) *(sl->ptr_spec));
+ free (CONST_CAST (*(sl->ptr_spec)));
*(sl->ptr_spec) = "";
sl->alloc_p = 0;
Don't repeat any we have already seen. */
if (multi_dir)
{
- free ((char *) multi_dir);
+ free (CONST_CAST (multi_dir));
multi_dir = NULL;
- free ((char *) multi_suffix);
+ free (CONST_CAST (multi_suffix));
multi_suffix = machine_suffix;
- free ((char *) just_multi_suffix);
+ free (CONST_CAST (just_multi_suffix));
just_multi_suffix = just_machine_suffix;
}
else
skip_multi_dir = true;
if (multi_os_dir)
{
- free ((char *) multi_os_dir);
+ free (CONST_CAST (multi_os_dir));
multi_os_dir = NULL;
}
else
if (multi_dir)
{
- free ((char *) multi_dir);
- free ((char *) multi_suffix);
- free ((char *) just_multi_suffix);
+ free (CONST_CAST (multi_dir));
+ free (CONST_CAST (multi_suffix));
+ free (CONST_CAST (just_multi_suffix));
}
if (multi_os_dir)
- free ((char *) multi_os_dir);
+ free (CONST_CAST (multi_os_dir));
if (ret != path)
free (path);
return ret;
errmsg = pex_run (pex,
((i + 1 == n_commands ? PEX_LAST : 0)
| (string == commands[i].prog ? PEX_SEARCH : 0)),
- string, (char * const *) commands[i].argv,
+ string, (char * const *) CONST_CAST (commands[i].argv),
NULL, NULL, &err);
if (errmsg != NULL)
{
}
if (string != commands[i].prog)
- free ((void *) string);
+ free (CONST_CAST (string));
}
execution_count++;
for (i = 0, j = 0; i < max; i++)
if (outfiles[i])
{
- argv[j] = (char *) outfiles[i];
+ argv[j] = (char *) CONST_CAST (outfiles[i]);
j++;
}
argv[j] = NULL;
while (length-- && !IS_DIR_SEPARATOR (arg[length]))
if (arg[length] == '.')
{
- ((char *)arg)[length] = 0;
+ ((char *)CONST_CAST(arg))[length] = 0;
dot = 1;
break;
}
do_spec_1 (arg, 1, NULL);
if (dot)
- ((char *)arg)[length] = '.';
+ ((char *)CONST_CAST(arg))[length] = '.';
do_spec_1 (suffix_subst, 1, NULL);
}
else
if (multilib_dir == NULL && multilib_os_dir != NULL
&& strcmp (multilib_os_dir, ".") == 0)
{
- free ((char *) multilib_os_dir);
+ free (CONST_CAST (multilib_os_dir));
multilib_os_dir = NULL;
}
else if (multilib_dir != NULL && multilib_os_dir == NULL)
l1 = strlen (s1);
l2 = strlen (s2);
- buf = XRESIZEVEC (char, s1, l1 + l2 + 1);
+ buf = XRESIZEVEC (char, CONST_CAST(s1), l1 + l2 + 1);
memcpy (buf + l1, s2, l2 + 1);
- XDELETE (s2);
+ XDELETE (CONST_CAST (s2));
s1 = buf;
}
return s1;
c2 = require (ID);
require (')');
r = concat ("VEC_", c1, "_", c2, (char *)0);
- free ((void *)c1);
- free ((void *)c2);
+ free (CONST_CAST (c1));
+ free (CONST_CAST (c2));
return r;
}
else
+2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * jcf-parse.c (read_class, java_parse_file): Use CONST_CAST.
+ * jcf.h (JCF_FINISH): Likewise.
+
2007-07-31 Nick Clifton <nickc@redhat.com>
* java-gimplify.c: Change copyright header to refer to version 3
if (path_name == 0)
return 0;
else
- free((char *) path_name);
+ free(CONST_CAST (path_name));
}
current_jcf = jcf;
file_list = list;
}
else
- list = (char *) main_input_filename;
+ list = (char *) CONST_CAST (main_input_filename);
while (list)
{
#define JCF_FINISH(JCF) { \
CPOOL_FINISH(&(JCF)->cpool); \
if ((JCF)->buffer) free ((JCF)->buffer); \
- if ((JCF)->filename) free ((char *) (JCF)->filename); \
- if ((JCF)->classname) free ((char *) (JCF)->classname); \
+ if ((JCF)->filename) free (CONST_CAST ((JCF)->filename)); \
+ if ((JCF)->classname) free (CONST_CAST ((JCF)->classname)); \
(JCF)->finished = 1; }
#define CPOOL_INIT(CPOOL) \
/* Flush and close dump file. */
if (dump_file_name)
{
- free ((char *) dump_file_name);
+ free (CONST_CAST (dump_file_name));
dump_file_name = NULL;
}
result = concat (key, &path[len], NULL);
if (free_key)
- free ((char *) key);
+ free (CONST_CAST (key));
result = translate_name (result);
}
else
{
if (pp->prefix != NULL)
{
- free ((char *) pp->prefix);
+ free (CONST_CAST (pp->prefix));
pp->prefix = NULL;
}
}
#endif /* GCC >= 3.0 */
+/* This macro allows casting away const-ness to pass -Wcast-qual
+ warnings. DO NOT USE THIS UNLESS YOU REALLY HAVE TO! It should
+ only be used in certain specific cases. One valid case is where
+ the C standard definitions or prototypes force you to. E.g. if you
+ need to free a const object, or if you pass a const string to
+ execv, et al. Another valid use would be in an allocation function
+ that creates const objects that need to be initialized. Most other
+ cases should be viewed with extreme caution. */
+#ifdef __GNUC__
+#define CONST_CAST(X) ((__extension__(union {__typeof(X)_q; void *_v;})(X))._v)
+#else
+#define CONST_CAST(X) ((void*)(X))
+#endif
+
#endif /* ! GCC_SYSTEM_H */
TREE_CONSTANT (s) = 1;
TREE_INVARIANT (s) = 1;
TREE_STRING_LENGTH (s) = len;
- memcpy ((char *) TREE_STRING_POINTER (s), str, len);
- ((char *) TREE_STRING_POINTER (s))[len] = '\0';
+ memcpy (CONST_CAST (TREE_STRING_POINTER (s)), str, len);
+ ((char *) CONST_CAST (TREE_STRING_POINTER (s)))[len] = '\0';
return s;
}