From 68a57691dc5d712bff5c70691dd90c0c670022d0 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Fri, 10 Aug 2007 17:53:58 +0000 Subject: system.h (CONST_CAST): New. * 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. 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. From-SVN: r127344 --- gcc/system.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gcc/system.h') diff --git a/gcc/system.h b/gcc/system.h index b96205b..46da381 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -766,4 +766,18 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #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 */ -- cgit v1.1