From: Torbjörn SVENSSON Date: Wed, 4 Feb 2026 13:23:44 +0000 (+0100) Subject: middle-end: replace CONST_CAST with const_cast<> [PR123892] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=458c7926d48959abcb2c1adaa22458e27459a551;p=thirdparty%2Fgcc.git middle-end: replace CONST_CAST with const_cast<> [PR123892] gcc/ChangeLog: PR middle-end/123892 * attribs.cc: Replace CONST_CAST with const_cast<>. * builtins.cc: Likewise. * collect2.cc: Likewise. * config/bpf/core-builtins.cc: Likewise. * config/gcn/mkoffload.cc: Likewise. * config/nvptx/mkoffload.cc: Likewise. * config/nvptx/nvptx.cc: Likewise. * ctfc.cc: Likewise. * dumpfile.cc: Likewise. * gcc.cc: Likewise. * gcov.cc: Likewise. * gengtype-parse.cc: Likewise. * gengtype-state.cc: Likewise. * gengtype.cc: Likewise. * genoutput.cc: Likewise. * ggc-page.cc: Likewise. * godump.cc: Likewise. * lto-section-in.cc: Likewise. * lto-wrapper.cc: Likewise. * omp-offload.cc: Likewise. * passes.cc: Likewise. * plugin.cc: Likewise. * prefix.cc: Likewise. * pretty-print.cc: Likewise. * selftest.cc: Likewise. * statistics.cc: Likewise. * stringpool.cc: Likewise. * tree.h: Likewise. * tree-profile.cc: Likewise. * vec.h: Likewise. * system.h (CONST_CAST2): Remove. (CONST_CAST): Likewise. * tsystem.h (CONST_CAST2): Remove. (CONST_CAST): Likewise. gcc/c-family/ChangeLog: PR middle-end/123892 * c-common.cc: Replace CONST_CAST with const_cast<>. * c-lex.cc: Likewise. gcc/c/ChangeLog: PR middle-end/123892 * c-decl.cc: Replace CONST_CAST with const_cast<>. * c-parser.cc: Likewise. gcc/cp/ChangeLog: PR middle-end/123892 * call.cc: Replace CONST_CAST with const_cast<>. * parser.cc: Likewise. gcc/d/ChangeLog: PR middle-end/123892 * d-builtins.cc: Replace CONST_CAST with const_cast<>. * d-incpath.cc: Likewise. * d-lang.cc: Likewise. * d-spec.cc: Likewise. * decl.cc: Likewise. gcc/fortran/ChangeLog: PR middle-end/123892 * gfortran.h: Replace CONST_CAST with const_cast<>. * module.cc: Likewise. * openmp.cc: Likewise. * options.cc: Likewise. * parse.cc: Likewise. * scanner.cc: Likewise. * st.cc: Likewise. * trans-intrinsic.cc: Likewise. gcc/lto/ChangeLog: PR middle-end/123892 * lto-common.cc: Replace CONST_CAST with const_cast<>. * lto.cc: Likewise. Signed-off-by: Torbjörn SVENSSON --- diff --git a/gcc/attribs.cc b/gcc/attribs.cc index ab79ca379ac..1205b2fc1df 100644 --- a/gcc/attribs.cc +++ b/gcc/attribs.cc @@ -371,7 +371,7 @@ register_scoped_attribute (const struct attribute_spec *attr, ->find_slot_with_hash (&str, substring_hash (str.str, str.length), INSERT); gcc_assert (!*slot || attr->name[0] == '*'); - *slot = CONST_CAST (struct attribute_spec *, attr); + *slot = const_cast (attr); } /* Return the spec for the scoped attribute with namespace NS and diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 28454c53777..692e20088c2 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -3788,12 +3788,12 @@ expand_builtin_memory_copy_args (tree dest, tree src, tree len, && CONST_INT_P (len_rtx) && (unsigned HOST_WIDE_INT) INTVAL (len_rtx) <= nbytes && can_store_by_pieces (INTVAL (len_rtx), builtin_memcpy_read_str, - CONST_CAST (char *, rep), + const_cast (rep), dest_align, false)) { dest_mem = store_by_pieces (dest_mem, INTVAL (len_rtx), builtin_memcpy_read_str, - CONST_CAST (char *, rep), + const_cast (rep), dest_align, false, retmode); dest_mem = force_operand (XEXP (dest_mem, 0), target); dest_mem = convert_memory_address (ptr_mode, dest_mem); @@ -4142,14 +4142,14 @@ expand_builtin_strncpy (tree exp, rtx target) if (!p || dest_align == 0 || !tree_fits_uhwi_p (len) || !can_store_by_pieces (tree_to_uhwi (len), builtin_strncpy_read_str, - CONST_CAST (char *, p), + const_cast (p), dest_align, false)) return NULL_RTX; dest_mem = get_memory_rtx (dest, len); store_by_pieces (dest_mem, tree_to_uhwi (len), builtin_strncpy_read_str, - CONST_CAST (char *, p), dest_align, false, + const_cast (p), dest_align, false, RETURN_BEGIN); dest_mem = force_operand (XEXP (dest_mem, 0), target); dest_mem = convert_memory_address (ptr_mode, dest_mem); @@ -4927,7 +4927,7 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq) result = emit_block_cmp_hints (arg1_rtx, arg2_rtx, len_rtx, TREE_TYPE (len), target, result_eq, constfn, - CONST_CAST (char *, rep), + const_cast (rep), tree_ctz (len)); if (result) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 7f891e1ef49..22d51162d9b 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -853,7 +853,7 @@ fix_string_type (tree value) { error ("size of string literal is too large"); length = tree_to_shwi (TYPE_MAX_VALUE (ssizetype)) / charsz * charsz; - char *str = CONST_CAST (char *, TREE_STRING_POINTER (value)); + char *str = const_cast (TREE_STRING_POINTER (value)); memset (str + length, '\0', MIN (TREE_STRING_LENGTH (value) - length, charsz)); TREE_STRING_LENGTH (value) = length; diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc index 4c0354e63a9..1750fbc3d06 100644 --- a/gcc/c-family/c-lex.cc +++ b/gcc/c-family/c-lex.cc @@ -174,7 +174,7 @@ cb_ident (cpp_reader * ARG_UNUSED (pfile), if (cpp_interpret_string (pfile, str, 1, &cstr, CPP_STRING)) { targetm.asm_out.output_ident ((const char *) cstr.text); - free (CONST_CAST (unsigned char *, cstr.text)); + free (const_cast (cstr.text)); } } } @@ -633,7 +633,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, (const char *) tok->val.str.text); TREE_TYPE (num_string) = char_array_type_node; num_string = fix_string_type (num_string); - str = CONST_CAST (char *, TREE_STRING_POINTER (num_string)); + str = const_cast (TREE_STRING_POINTER (num_string)); str[len] = '\0'; literal = build_userdef_literal (suffix_id, *value, overflow, num_string); @@ -1700,7 +1700,7 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate) (parse_in, strs, concats + 1, &istr, type)) { value = build_string (istr.len, (const char *) istr.text); - free (CONST_CAST (unsigned char *, istr.text)); + free (const_cast (istr.text)); if (concats) { gcc_assert (locs); diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index ea0eaec0bb5..f2440a0a630 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5015,7 +5015,7 @@ c_make_fname_decl (location_t loc, tree id, int type_dep) DECL_ARTIFICIAL (decl) = 1; init = build_string (length + 1, name); - free (CONST_CAST (char *, name)); + free (const_cast (name)); TREE_TYPE (init) = type; DECL_INITIAL (decl) = init; diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 5ab3d84ea80..9816a9425ce 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -9893,7 +9893,7 @@ c_parser_string_literal (c_parser *parser, bool translate, bool wide_ok) (parse_in, strs, count, &istr, type))) { value = build_string (istr.len, (const char *) istr.text); - free (CONST_CAST (unsigned char *, istr.text)); + free (const_cast (istr.text)); if (count > 1) { location_t *locs = (location_t *) obstack_finish (&loc_ob); diff --git a/gcc/collect2.cc b/gcc/collect2.cc index cebdb488781..4353be6e3e7 100644 --- a/gcc/collect2.cc +++ b/gcc/collect2.cc @@ -2760,7 +2760,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass, non-const char * filename parameter, even though it will not modify that string. So we must cast away const-ness here, using CONST_CAST to prevent complaints from -Wcast-qual. */ - if ((ldptr = ldopen (CONST_CAST (char *, prog_name), ldptr)) != NULL) + if ((ldptr = ldopen (const_cast (prog_name), ldptr)) != NULL) { if (! MY_ISCOFF (HEADER (ldptr).f_magic)) { diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index 9eca8a7a55f..d366b7c06a4 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -799,7 +799,7 @@ process_field_expr (struct cr_builtins *data) for (int i = 0; i < nr_accessors; i++) n += snprintf (str + n, sizeof (str) - n, i == 0 ? "%u" : ":%u", accessors[i]); - ret.str = CONST_CAST (char *, ggc_strdup (str)); + ret.str = const_cast (ggc_strdup (str)); } else gcc_unreachable (); @@ -916,7 +916,7 @@ process_enum_value (struct cr_builtins *data) in 6 chars. */ char tmp[6]; sprintf (tmp, "%u", index); - ret.str = CONST_CAST (char *, ggc_strdup(tmp)); + ret.str = const_cast (ggc_strdup (tmp)); return ret; } diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 2bad9b4e2d3..71e11f0f307 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -182,7 +182,7 @@ xputenv (const char *string) { if (verbose) fprintf (stderr, "%s\n", string); - putenv (CONST_CAST (char *, string)); + putenv (const_cast (string)); } /* Parse STR, saving found tokens into PVALUES and return their number. @@ -839,7 +839,7 @@ compile_native (const char *infile, const char *outfile, const char *compiler, obstack_ptr_grow (&argv_obstack, NULL); const char **new_argv = XOBFINISH (&argv_obstack, const char **); - fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true, + fork_execute (new_argv[0], const_cast (new_argv), true, ".gccnative_args"); obstack_free (&argv_obstack, NULL); } @@ -1366,8 +1366,10 @@ main (int argc, char **argv) obstack_ptr_grow (&files_to_cleanup, omp_requires_file); /* Run the compiler pass. */ - xputenv (concat ("GCC_OFFLOAD_OMP_REQUIRES_FILE=", omp_requires_file, NULL)); - fork_execute (cc_argv[0], CONST_CAST (char **, cc_argv), true, ".gcc_args"); + xputenv (concat ("GCC_OFFLOAD_OMP_REQUIRES_FILE=", omp_requires_file, + NULL)); + fork_execute (cc_argv[0], const_cast (cc_argv), true, + ".gcc_args"); obstack_free (&cc_argv_obstack, NULL); unsetenv("GCC_OFFLOAD_OMP_REQUIRES_FILE"); @@ -1395,7 +1397,8 @@ main (int argc, char **argv) fclose (out); /* Run the assemble/link pass. */ - fork_execute (ld_argv[0], CONST_CAST (char **, ld_argv), true, ".ld_args"); + fork_execute (ld_argv[0], const_cast (ld_argv), true, + ".ld_args"); obstack_free (&ld_argv_obstack, NULL); process_obj (gcn_o_name, cfile, omp_requires); diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 3d61339e875..6a2a3bc939b 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -104,7 +104,7 @@ xputenv (const char *string) { if (verbose) fprintf (stderr, "%s\n", string); - putenv (CONST_CAST (char *, string)); + putenv (const_cast (string)); } @@ -625,7 +625,7 @@ compile_native (const char *infile, const char *outfile, const char *compiler, obstack_ptr_grow (&argv_obstack, NULL); const char **new_argv = XOBFINISH (&argv_obstack, const char **); - fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true, + fork_execute (new_argv[0], const_cast (new_argv), true, ".gccnative_args"); obstack_free (&argv_obstack, NULL); } @@ -842,7 +842,7 @@ main (int argc, char **argv) omp_requires_file = make_temp_file (".mkoffload.omp_requires"); xputenv (concat ("GCC_OFFLOAD_OMP_REQUIRES_FILE=", omp_requires_file, NULL)); - fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true, + fork_execute (new_argv[0], const_cast (new_argv), true, ".gcc_args"); obstack_free (&argv_obstack, NULL); unsetenv("GCC_OFFLOAD_OMP_REQUIRES_FILE"); diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index dbe788c7bbc..4cee096cca5 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -513,7 +513,7 @@ section_for_sym (rtx sym) static const char * section_for_decl (const_tree decl) { - return section_for_sym (XEXP (DECL_RTL (CONST_CAST (tree, decl)), 0)); + return section_for_sym (XEXP (DECL_RTL (const_cast (decl)), 0)); } /* Check NAME for special function names and redirect them by returning a diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 979343e8329..c23a615fa1a 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -11848,7 +11848,7 @@ name_as_c_string (tree name, tree type, bool *free_p) else pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name)); - return CONST_CAST (char *, pretty_name); + return const_cast (pretty_name); } /* If CANDIDATES contains exactly one candidate, return it, otherwise diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 4d988c27cb8..5f1d028de0c 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -5024,7 +5024,7 @@ cp_parser_string_literal_common (cp_parser *parser, bool translate, (parse_in, strs, count, &istr, type)) { value = build_string (istr.len, (const char *)istr.text); - free (CONST_CAST (unsigned char *, istr.text)); + free (const_cast (istr.text)); if (count > 1) { location_t *locs = (location_t *)obstack_finish (&loc_ob); diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc index 4609b3dc321..8beca20df8c 100644 --- a/gcc/ctfc.cc +++ b/gcc/ctfc.cc @@ -292,7 +292,7 @@ ctfc_strtable_add_str (ctf_strtable_t * str_table, const char * name, not add null strings, return the offset to the empty string for them. */ if ((!name || (name != NULL && !strcmp (name, ""))) && str_offset) { - ctf_string = CONST_CAST (char *, str_table->ctstab_estr); + ctf_string = const_cast (str_table->ctstab_estr); str_offset = 0; } else @@ -300,7 +300,7 @@ ctfc_strtable_add_str (ctf_strtable_t * str_table, const char * name, gcc_assert (name); /* Add null-terminated strings to the string table. */ len = strlen (name) + 1; - ctf_string = CONST_CAST (char *, ggc_strdup (name)); + ctf_string = const_cast (ggc_strdup (name)); ctfc_strtable_append_str (str_table, ctf_string); /* Add string to the string table. Keep number of strings updated. */ @@ -357,7 +357,7 @@ ctf_add_cuname (ctf_container_ref ctfc, const char * filename) } else /* Filename is an absolute path. */ - cuname = CONST_CAST (char *, ggc_strdup (filename)); + cuname = const_cast (ggc_strdup (filename)); ctf_add_string (ctfc, cuname, &(ctfc->ctfc_cuname_offset)); /* Add 1 as CTF strings in the CTF string table are null-terminated diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index dce03e9f53b..4f42c11cd7d 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -386,7 +386,7 @@ d_eval_constant_expression (const Loc &loc, tree cst) { const void *string = TREE_STRING_POINTER (cst); size_t len = TREE_STRING_LENGTH (cst) - 1; - return StringExp::create (loc, CONST_CAST (void *, string), len); + return StringExp::create (loc, const_cast (string), len); } else if (code == VECTOR_CST) { diff --git a/gcc/d/d-incpath.cc b/gcc/d/d-incpath.cc index aaafc77b0a0..61565005922 100644 --- a/gcc/d/d-incpath.cc +++ b/gcc/d/d-incpath.cc @@ -77,7 +77,7 @@ add_globalpaths (Strings &paths) if (target == NULL || !FileName::exists (target)) { if (target) - free (CONST_CAST (char *, target)); + free (const_cast (target)); continue; } @@ -97,7 +97,7 @@ add_filepaths (Strings &paths) if (!FileName::exists (target)) { - free (CONST_CAST (char *, target)); + free (const_cast (target)); continue; } diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index a522e51f5a2..815b1782a65 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -455,7 +455,7 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, break; case OPT_fdebug_: - if (Identifier::isValidIdentifier (CONST_CAST (char *, arg))) + if (Identifier::isValidIdentifier (const_cast (arg))) { DebugCondition::addGlobalIdent (arg); break; @@ -700,7 +700,7 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, break; case OPT_fversion_: - if (Identifier::isValidIdentifier (CONST_CAST (char *, arg))) + if (Identifier::isValidIdentifier (const_cast (arg))) { VersionCondition::addGlobalIdent (arg); break; diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc index c4600b2e9f4..2993d3475b4 100644 --- a/gcc/d/d-spec.cc +++ b/gcc/d/d-spec.cc @@ -162,7 +162,7 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, break; case OPT_defaultlib_: - free (CONST_CAST (char *, defaultlib)); + free (const_cast (defaultlib)); if (arg != NULL) { args[i] |= SKIPOPT; @@ -171,7 +171,7 @@ lang_specific_driver (cl_decoded_option **in_decoded_options, break; case OPT_debuglib_: - free (CONST_CAST (char *, debuglib)); + free (const_cast (debuglib)); if (arg != NULL) { args[i] |= SKIPOPT; diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 2614277d96a..b95fd1a2521 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -2055,7 +2055,7 @@ make_thunk (FuncDeclaration *decl, int offset) unsigned identlen = IDENTIFIER_LENGTH (target_name) + 14; ident = XNEWVEC (const char, identlen); - snprintf (CONST_CAST (char *, ident), identlen, + snprintf (const_cast (ident), identlen, "_DTi%u%s", offset, IDENTIFIER_POINTER (target_name)); } @@ -2065,7 +2065,7 @@ make_thunk (FuncDeclaration *decl, int offset) d_keep (thunk); if (decl->resolvedLinkage () != LINK::cpp) - free (CONST_CAST (char *, ident)); + free (const_cast (ident)); /* Thunks are connected to the definitions of the functions, so thunks are not produced for external functions. */ diff --git a/gcc/dumpfile.cc b/gcc/dumpfile.cc index 2541fab85ca..a309877773d 100644 --- a/gcc/dumpfile.cc +++ b/gcc/dumpfile.cc @@ -1733,7 +1733,7 @@ dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename) dump_files[i].pstate = 1; } if (old_filename && filename != old_filename) - free (CONST_CAST (char *, old_filename)); + free (const_cast (old_filename)); } } @@ -1754,7 +1754,7 @@ dump_enable_all (dump_kind dkind, dump_flags_t flags, const char *filename) m_extra_dump_files[i].pstate = 1; } if (old_filename && filename != old_filename) - free (CONST_CAST (char *, old_filename)); + free (const_cast (old_filename)); } } @@ -1807,7 +1807,7 @@ gcc::dump_manager::update_dfi_for_opt_info (dump_file_info *dfi) const if (m_optinfo_filename) dfi->alt_filename = xstrdup (m_optinfo_filename); if (old_filename && m_optinfo_filename != old_filename) - free (CONST_CAST (char *, old_filename)); + free (const_cast (old_filename)); return true; } @@ -1904,7 +1904,7 @@ dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob) if (filename) { if (dfi->pfilename) - free (CONST_CAST (char *, dfi->pfilename)); + free (const_cast (dfi->pfilename)); dfi->pfilename = xstrdup (filename); } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 37b24f97fa3..dda5b6262bf 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3571,7 +3571,12 @@ vec_push (char **&optr, size_t &osz, const char *elt) /* {auto,}vec.safe_push () replacement. Don't ask.. */ // if (strlen (elt) < 4) return; premature optimization: eliminated by cutoff optr = XRESIZEVEC (char *, optr, osz + 2); - optr[osz] = CONST_CAST (char *, elt); + optr[osz] = +#ifdef __cplusplus + const_cast (elt); +#else + (__extension__ (union {const char *_q; const char *_nq;})(elt))._nq; +#endif optr[++osz] = NULL; } diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc index eda0bc9e299..47b1c943132 100644 --- a/gcc/fortran/module.cc +++ b/gcc/fortran/module.cc @@ -3936,10 +3936,9 @@ mio_expr (gfc_expr **ep) break; case EXPR_SUBSTRING: - e->value.character.string - = CONST_CAST (gfc_char_t *, - mio_allocated_wide_string (e->value.character.string, - e->value.character.length)); + e->value.character.string = const_cast + (mio_allocated_wide_string (e->value.character.string, + e->value.character.length)); mio_ref_list (&e->ref); break; @@ -3976,10 +3975,9 @@ mio_expr (gfc_expr **ep) hwi = e->value.character.length; mio_hwi (&hwi); e->value.character.length = hwi; - e->value.character.string - = CONST_CAST (gfc_char_t *, - mio_allocated_wide_string (e->value.character.string, - e->value.character.length)); + e->value.character.string = const_cast + (mio_allocated_wide_string (e->value.character.string, + e->value.character.length)); break; default: diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index af3cb54ad56..11876162d60 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -223,7 +223,7 @@ gfc_free_omp_clauses (gfc_omp_clauses *c) gfc_free_expr_list (c->wait_list); gfc_free_expr_list (c->tile_list); gfc_free_expr_list (c->sizes_list); - free (CONST_CAST (char *, c->critical_name)); + free (const_cast (c->critical_name)); if (c->assume) { free (c->assume->absent); diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc index 13b0ffb4538..925a1e38dcf 100644 --- a/gcc/fortran/options.cc +++ b/gcc/fortran/options.cc @@ -370,7 +370,7 @@ gfc_post_options (const char **pfilename) gfc_add_include_path (".", true, true, false, false); if (canon_source_file != gfc_source_file) - free (CONST_CAST (char *, canon_source_file)); + free (const_cast (canon_source_file)); /* Decide which form the file will be read in as. */ diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 413d0666df7..e397ea6015c 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -6435,7 +6435,7 @@ parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only) new_st.ext.omp_name) != 0)) gfc_error ("Name after !$omp critical and !$omp end critical does " "not match at %C"); - free (CONST_CAST (char *, new_st.ext.omp_name)); + free (const_cast (new_st.ext.omp_name)); new_st.ext.omp_name = NULL; break; case EXEC_OMP_END_SINGLE: diff --git a/gcc/fortran/scanner.cc b/gcc/fortran/scanner.cc index 1e18385b5bf..6bdbe5593ce 100644 --- a/gcc/fortran/scanner.cc +++ b/gcc/fortran/scanner.cc @@ -173,9 +173,7 @@ wide_strchr (const gfc_char_t *s, gfc_char_t c) { do { if (*s == c) - { - return CONST_CAST(gfc_char_t *, s); - } + return const_cast (s); } while (*s++); return 0; } diff --git a/gcc/fortran/st.cc b/gcc/fortran/st.cc index edf52912a85..ce4fcad884f 100644 --- a/gcc/fortran/st.cc +++ b/gcc/fortran/st.cc @@ -295,7 +295,7 @@ gfc_free_statement (gfc_code *p) break; case EXEC_OMP_END_CRITICAL: - free (CONST_CAST (char *, p->ext.omp_name)); + free (const_cast (p->ext.omp_name)); break; case EXEC_OMP_FLUSH: diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index cfdd0258241..ec98f967200 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -675,7 +675,7 @@ gfc_adjust_builtins (void) for (hash_map::iterator it = gfc_vectorized_builtins->begin (); it != gfc_vectorized_builtins->end (); ++it) - free (CONST_CAST (char *, (*it).first)); + free (const_cast ((*it).first)); delete gfc_vectorized_builtins; gfc_vectorized_builtins = NULL; diff --git a/gcc/gcc.cc b/gcc/gcc.cc index bc66b795df0..065f69c9d8b 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -146,7 +146,7 @@ env_manager::xput (const char *string) m_keys.safe_push (kv); } - ::putenv (CONST_CAST (char *, string)); + ::putenv (const_cast (string)); } /* Undo any xputenv changes made since last restore. @@ -2155,7 +2155,7 @@ set_spec (const char *name, const char *spec, bool user_p) /* Free the old spec. */ if (old_spec && sl->alloc_p) - free (CONST_CAST (char *, old_spec)); + free (const_cast (old_spec)); sl->user_p = user_p; sl->alloc_p = true; @@ -2316,7 +2316,7 @@ close_at_file (void) /* Copy the strings over. */ for (i = 0; i < n_args; i++) - argv[i] = CONST_CAST (char *, at_file_argbuf[i]); + argv[i] = const_cast (at_file_argbuf[i]); argv[i] = NULL; at_file_argbuf.truncate (0); @@ -2568,7 +2568,7 @@ read_specs (const char *filename, bool main_p, bool user_p) set_spec (p2, *(sl->ptr_spec), user_p); if (sl->alloc_p) - free (CONST_CAST (char *, *(sl->ptr_spec))); + free (const_cast (*(sl->ptr_spec))); *(sl->ptr_spec) = ""; sl->alloc_p = 0; @@ -2944,18 +2944,18 @@ for_each_path (const struct path_prefix *paths, Don't repeat any we have already seen. */ if (multi_dir) { - free (CONST_CAST (char *, multi_dir)); + free (const_cast (multi_dir)); multi_dir = NULL; - free (CONST_CAST (char *, multi_suffix)); + free (const_cast (multi_suffix)); multi_suffix = machine_suffix; - free (CONST_CAST (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 (CONST_CAST (char *, multi_os_dir)); + free (const_cast (multi_os_dir)); multi_os_dir = NULL; } else @@ -2964,12 +2964,12 @@ for_each_path (const struct path_prefix *paths, if (multi_dir) { - free (CONST_CAST (char *, multi_dir)); - free (CONST_CAST (char *, multi_suffix)); - free (CONST_CAST (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 (CONST_CAST (char *, multi_os_dir)); + free (const_cast (multi_os_dir)); if (ret != path) free (path); return ret; @@ -3454,7 +3454,7 @@ execute (void) errmsg = pex_run (pex, ((i + 1 == n_commands ? PEX_LAST : 0) | (string == commands[i].prog ? PEX_SEARCH : 0)), - string, CONST_CAST (char **, commands[i].argv), + string, const_cast (commands[i].argv), NULL, NULL, &err); if (errmsg != NULL) { @@ -3466,7 +3466,7 @@ execute (void) } if (i && string != commands[i].prog) - free (CONST_CAST (char *, string)); + free (const_cast (string)); } execution_count++; @@ -3610,7 +3610,7 @@ execute (void) } if (commands[0].argv[0] != commands[0].prog) - free (CONST_CAST (char *, commands[0].argv[0])); + free (const_cast (commands[0].argv[0])); return ret_code; } @@ -7703,13 +7703,13 @@ give_switch (int switchnum, int omit_first_word) while (length-- && !IS_DIR_SEPARATOR (arg[length])) if (arg[length] == '.') { - (CONST_CAST (char *, arg))[length] = 0; + (const_cast (arg))[length] = 0; dot = 1; break; } do_spec_1 (arg, 1, NULL); if (dot) - (CONST_CAST (char *, arg))[length] = '.'; + (const_cast (arg))[length] = '.'; do_spec_1 (suffix_subst, 1, NULL); } else @@ -10148,7 +10148,7 @@ set_multilib_dir (void) if (multilib_dir == NULL && multilib_os_dir != NULL && strcmp (multilib_os_dir, ".") == 0) { - free (CONST_CAST (char *, multilib_os_dir)); + free (const_cast (multilib_os_dir)); multilib_os_dir = NULL; } else if (multilib_dir != NULL && multilib_os_dir == NULL) diff --git a/gcc/gcov.cc b/gcc/gcov.cc index 5bed44841c0..6256caa19e9 100644 --- a/gcc/gcov.cc +++ b/gcc/gcov.cc @@ -2091,7 +2091,7 @@ create_file_names (const char *file_name) } /* Remove the extension. */ - cptr = strrchr (CONST_CAST (char *, lbasename (name)), '.'); + cptr = strrchr (const_cast (lbasename (name)), '.'); if (cptr) *cptr = 0; diff --git a/gcc/gengtype-parse.cc b/gcc/gengtype-parse.cc index 530e4f78278..962d94390a7 100644 --- a/gcc/gengtype-parse.cc +++ b/gcc/gengtype-parse.cc @@ -237,9 +237,9 @@ string_seq (void) l1 = strlen (s1); l2 = strlen (s2); - buf = XRESIZEVEC (char, CONST_CAST (char *, s1), l1 + l2 + 1); + buf = XRESIZEVEC (char, const_cast (s1), l1 + l2 + 1); memcpy (buf + l1, s2, l2 + 1); - XDELETE (CONST_CAST (char *, s2)); + XDELETE (const_cast (s2)); s1 = buf; } return s1; diff --git a/gcc/gengtype-state.cc b/gcc/gengtype-state.cc index 42bc1d2b00b..4f69bae3620 100644 --- a/gcc/gengtype-state.cc +++ b/gcc/gengtype-state.cc @@ -52,7 +52,7 @@ type_lineloc (const_type_p ty) case TYPE_LANG_STRUCT: case TYPE_USER_STRUCT: case TYPE_UNDEFINED: - return CONST_CAST (struct fileloc*, &ty->u.s.line); + return const_cast (&ty->u.s.line); case TYPE_SCALAR: case TYPE_STRING: case TYPE_POINTER: diff --git a/gcc/gengtype.cc b/gcc/gengtype.cc index 159d424f145..5860f9875ed 100644 --- a/gcc/gengtype.cc +++ b/gcc/gengtype.cc @@ -2060,8 +2060,8 @@ header_dot_h_frul (input_file* inpf, char**poutname, static outf_p source_dot_cc_frul (input_file* inpf, char**poutname, char**pforname) { - char *newbasename = CONST_CAST (char*, get_file_basename (inpf)); - char *newoutname = CONST_CAST (char*, get_file_gtfilename (inpf)); + char *newbasename = const_cast (get_file_basename (inpf)); + char *newoutname = const_cast (get_file_gtfilename (inpf)); DBGPRINTF ("inpf %p inpname %s original outname %s forname %s", (void*) inpf, get_input_file_name (inpf), *poutname, *pforname); @@ -2529,7 +2529,7 @@ output_mangled_typename (outf_p of, const_type_p t) oprintf (of, "%lu%s", (unsigned long) strlen (id_for_tag), id_for_tag); if (id_for_tag != t->u.s.tag) - free (CONST_CAST (char *, id_for_tag)); + free (const_cast (id_for_tag)); } break; case TYPE_ARRAY: @@ -3303,7 +3303,7 @@ get_output_file_for_structure (const_type_p s) /* The call to get_output_file_with_visibility may update fn by caching its result inside, so we need the CONST_CAST. */ - return get_output_file_with_visibility (CONST_CAST (input_file*, fn)); + return get_output_file_with_visibility (const_cast (fn)); } @@ -3368,7 +3368,7 @@ write_marker_function_name (outf_p of, type_p s, const char *prefix) const char *id_for_tag = filter_type_name (s->u.s.tag); oprintf (of, "gt_%sx_%s", prefix, id_for_tag); if (id_for_tag != s->u.s.tag) - free (CONST_CAST (char *, id_for_tag)); + free (const_cast (id_for_tag)); } else gcc_unreachable (); @@ -3710,7 +3710,7 @@ write_types (outf_p output_header, type_p structures, "#define gt_%sx_%s gt_%sx_%s\n", wtd->prefix, s->u.s.tag, wtd->prefix, t_id_for_tag); if (t_id_for_tag != t->u.s.tag) - free (CONST_CAST (char *, t_id_for_tag)); + free (const_cast (t_id_for_tag)); } else error_at_line (&s->u.s.line, @@ -3726,7 +3726,7 @@ write_types (outf_p output_header, type_p structures, wtd->prefix, s_id_for_tag); if (s_id_for_tag != s->u.s.tag) - free (CONST_CAST (char *, s_id_for_tag)); + free (const_cast (s_id_for_tag)); if (s->u.s.line.file == NULL) { @@ -4113,7 +4113,7 @@ put_mangled_filename (outf_p f, const input_file *inpf) /* The call to get_output_file_name may indirectly update fn since get_output_file_with_visibility caches its result inside, so we need the CONST_CAST. */ - const char *name = get_output_file_name (CONST_CAST (input_file*, inpf)); + const char *name = get_output_file_name (const_cast (inpf)); if (!f || !name) return; for (; *name != 0; name++) @@ -4427,7 +4427,7 @@ write_root (outf_p f, pair_p v, type_p type, const char *name, int has_length, else oprintf (f, " NULL"); if (id_for_tag != tp->u.s.tag) - free (CONST_CAST (char *, id_for_tag)); + free (const_cast (id_for_tag)); } else if (has_length && (tp->kind == TYPE_POINTER || union_or_struct_p (tp))) @@ -4531,7 +4531,7 @@ write_roots (pair_p variables, bool emit_pch) for (v = variables; v; v = v->next) { outf_p f = - get_output_file_with_visibility (CONST_CAST (input_file*, + get_output_file_with_visibility (const_cast ( v->line.file)); struct flist *fli; const char *length = NULL; @@ -4584,7 +4584,7 @@ write_roots (pair_p variables, bool emit_pch) for (v = variables; v; v = v->next) { - outf_p f = get_output_file_with_visibility (CONST_CAST (input_file*, + outf_p f = get_output_file_with_visibility (const_cast ( v->line.file)); struct flist *fli; int skip_p = 0; @@ -4620,7 +4620,7 @@ write_roots (pair_p variables, bool emit_pch) for (v = variables; v; v = v->next) { - outf_p f = get_output_file_with_visibility (CONST_CAST (input_file*, + outf_p f = get_output_file_with_visibility (const_cast ( v->line.file)); struct flist *fli; int skip_p = 1; @@ -4654,7 +4654,7 @@ write_roots (pair_p variables, bool emit_pch) for (v = variables; v; v = v->next) { - outf_p f = get_output_file_with_visibility (CONST_CAST (input_file*, + outf_p f = get_output_file_with_visibility (const_cast ( v->line.file)); struct flist *fli; options_p o; @@ -4689,7 +4689,7 @@ write_roots (pair_p variables, bool emit_pch) for (v = variables; v; v = v->next) { - outf_p f = get_output_file_with_visibility (CONST_CAST (input_file*, + outf_p f = get_output_file_with_visibility (const_cast ( v->line.file)); struct flist *fli; int skip_p = 0; diff --git a/gcc/genoutput.cc b/gcc/genoutput.cc index a004fd7edbf..cab03964885 100644 --- a/gcc/genoutput.cc +++ b/gcc/genoutput.cc @@ -1302,7 +1302,7 @@ note_constraint (md_rtx_info *info) new_cdata = XNEWVAR (class constraint_data, sizeof (class constraint_data) + namelen); new (new_cdata) constraint_data (); - strcpy (CONST_CAST (char *, new_cdata->name), name); + strcpy (const_cast (new_cdata->name), name); new_cdata->namelen = namelen; new_cdata->loc = info->loc; new_cdata->next_this_letter = *slot; diff --git a/gcc/ggc-page.cc b/gcc/ggc-page.cc index 99023990cbf..e3cccc9d079 100644 --- a/gcc/ggc-page.cc +++ b/gcc/ggc-page.cc @@ -1589,7 +1589,7 @@ gt_ggc_m_S (const void *p) a STRING_CST. */ gcc_assert (offset == offsetof (struct tree_string, str)); p = ((const char *) p) - offset; - gt_ggc_mx_lang_tree_node (CONST_CAST (void *, p)); + gt_ggc_mx_lang_tree_node (const_cast (p)); return; } diff --git a/gcc/godump.cc b/gcc/godump.cc index c6bb1763e7f..9fe693d9a39 100644 --- a/gcc/godump.cc +++ b/gcc/godump.cc @@ -465,7 +465,7 @@ go_undef (unsigned int lineno, const char *buffer) real_debug_hooks->undef (lineno, buffer); - mhval.name = CONST_CAST (char *, buffer); + mhval.name = const_cast (buffer); mhval.value = NULL; slot = htab_find_slot (macro_hash, &mhval, NO_INSERT); if (slot != NULL) @@ -1186,14 +1186,14 @@ go_output_typedef (class godump_container *container, tree decl) slot = htab_find_slot (container->type_hash, type, INSERT); if (*slot != NULL) return; - *slot = CONST_CAST (void *, (const void *) type); + *slot = const_cast ((const void *) type); if (!go_format_type (container, original_type, true, false, NULL, false)) { fprintf (go_dump_file, "// "); slot = htab_find_slot (container->invalid_hash, type, INSERT); - *slot = CONST_CAST (void *, (const void *) type); + *slot = const_cast ((const void *) type); } fprintf (go_dump_file, "type _%s ", IDENTIFIER_POINTER (DECL_NAME (decl))); @@ -1225,14 +1225,14 @@ go_output_typedef (class godump_container *container, tree decl) slot = htab_find_slot (container->type_hash, type, INSERT); if (*slot != NULL) return; - *slot = CONST_CAST (void *, (const void *) type); + *slot = const_cast ((const void *) type); if (!go_format_type (container, TREE_TYPE (decl), false, false, NULL, false)) { fprintf (go_dump_file, "// "); slot = htab_find_slot (container->invalid_hash, type, INSERT); - *slot = CONST_CAST (void *, (const void *) type); + *slot = const_cast ((const void *) type); } fprintf (go_dump_file, "type _%s ", IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl)))); @@ -1352,7 +1352,7 @@ keyword_hash_init (class godump_container *container) for (i = 0; i < count; i++) { slot = htab_find_slot (container->keyword_hash, keywords[i], INSERT); - *slot = CONST_CAST (void *, (const void *) keywords[i]); + *slot = const_cast ((const void *) keywords[i]); } } diff --git a/gcc/lto-section-in.cc b/gcc/lto-section-in.cc index f23354dbc79..c57f84f02bd 100644 --- a/gcc/lto-section-in.cc +++ b/gcc/lto-section-in.cc @@ -225,7 +225,7 @@ lto_free_section_data (struct lto_file_decl_data *file_data, /* The underlying data address has been extracted from the mapping header. Free that, then free the allocated uncompression buffer. */ (free_section_f) (file_data, section_type, name, header->data, header->len); - free (CONST_CAST (char *, real_data)); + free (const_cast (real_data)); } /* Free data allocated by lto_get_raw_section_data. */ @@ -321,8 +321,8 @@ renaming_slot_free (void *slot) { struct lto_renaming_slot *s = (struct lto_renaming_slot *) slot; - free (CONST_CAST (void *, (const void *) s->old_name)); - free (CONST_CAST (void *, (const void *) s->new_name)); + free (const_cast ((const void *) s->old_name)); + free (const_cast ((const void *) s->new_name)); free ((void *) s); } diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc index a15f0e259e5..c300655b1d8 100644 --- a/gcc/lto-wrapper.cc +++ b/gcc/lto-wrapper.cc @@ -1401,7 +1401,7 @@ make_exists (void) int exit_status = 0; int err = 0; const char *errmsg - = pex_one (PEX_SEARCH, make_args[0], CONST_CAST (char **, make_args), + = pex_one (PEX_SEARCH, make_args[0], const_cast (make_args), "make", NULL, NULL, &exit_status, &err); freeargv (make_argv); return errmsg == NULL && exit_status == 0 && err == 0; @@ -1929,7 +1929,7 @@ cont1: new_argv = XOBFINISH (&argv_obstack, const char **); argv_ptr = &new_argv[new_head_argc]; - fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true, + fork_execute (new_argv[0], const_cast (new_argv), true, "ltrans_args"); /* Copy the early generated debug info from the objects to temporary @@ -2154,7 +2154,7 @@ cont: snprintf (argsuffix, sizeof (DUMPBASE_SUFFIX) + sizeof (".ltrans_args"), "ltrans%u.ltrans_args", i); - fork_execute (new_argv[0], CONST_CAST (char **, new_argv), + fork_execute (new_argv[0], const_cast (new_argv), true, save_temps ? argsuffix : NULL); if (!ltrans_cache) maybe_unlink (input_names[i]); @@ -2206,7 +2206,7 @@ cont: obstack_ptr_grow (&argv_obstack, NULL); new_argv = XOBFINISH (&argv_obstack, const char **); - pex = collect_execute (new_argv[0], CONST_CAST (char **, new_argv), + pex = collect_execute (new_argv[0], const_cast (new_argv), NULL, NULL, PEX_SEARCH, false, NULL); do_wait (new_argv[0], pex); freeargv (make_argv); diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc index 17bbc8d8412..cc513b84ef1 100644 --- a/gcc/lto/lto-common.cc +++ b/gcc/lto/lto-common.cc @@ -96,7 +96,7 @@ free_with_string (void *arg) { struct lto_section_slot *s = (struct lto_section_slot *)arg; - free (CONST_CAST (char *, s->name)); + free (const_cast (s->name)); free (arg); } @@ -2504,7 +2504,7 @@ get_section_data (struct lto_file_decl_data *file_data, *len = f_slot->len; } - free (CONST_CAST (char *, section_name)); + free (const_cast (section_name)); return data; } @@ -2531,7 +2531,7 @@ free_section_data (struct lto_file_decl_data *file_data ATTRIBUTE_UNUSED, munmap ((caddr_t) computed_offset, computed_len); #else - free (CONST_CAST(char *, offset)); + free (const_cast (offset)); #endif } diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc index 0a3032c7c00..9589c6ca5ab 100644 --- a/gcc/lto/lto.cc +++ b/gcc/lto/lto.cc @@ -180,7 +180,7 @@ stream_out (char *temp_filename, lto_symtab_encoder_t encoder, int part) streamer_dump_file = dump_begin (TDI_lto_stream_out, NULL, part); ipa_write_optimization_summaries (encoder, part == 0); - free (CONST_CAST (char *, file->filename)); + free (const_cast (file->filename)); lto_set_current_out_file (NULL); lto_obj_file_close (file); diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc index 10038749333..8522644eabc 100644 --- a/gcc/omp-offload.cc +++ b/gcc/omp-offload.cc @@ -916,7 +916,7 @@ oacc_parse_default_dims (const char *dims) const char *eptr; errno = 0; - val = strtol (pos, CONST_CAST (char **, &eptr), 10); + val = strtol (pos, const_cast (&eptr), 10); if (errno || val <= 0 || (int) val != val) goto malformed; pos = eptr; diff --git a/gcc/passes.cc b/gcc/passes.cc index a7e8d4a8f18..9ec37eeb2a9 100644 --- a/gcc/passes.cc +++ b/gcc/passes.cc @@ -887,7 +887,7 @@ pass_manager::register_one_dump_file (opt_pass *pass) set_pass_for_id (id, pass); full_name = concat (prefix, pass->name, num, NULL); register_pass_name (pass, full_name); - free (CONST_CAST (char *, full_name)); + free (const_cast (full_name)); } /* Register the dump files for the pass_manager starting at PASS. */ @@ -2207,7 +2207,7 @@ release_dump_file_name (void) { if (dump_file_name) { - free (CONST_CAST (char *, dump_file_name)); + free (const_cast (dump_file_name)); dump_file_name = NULL; } } diff --git a/gcc/plugin.cc b/gcc/plugin.cc index 7e8837c5301..436be5e0147 100644 --- a/gcc/plugin.cc +++ b/gcc/plugin.cc @@ -186,7 +186,7 @@ add_new_plugin (const char* plugin_name) if (name_is_short) { - base_name = CONST_CAST (char*, plugin_name); + base_name = const_cast (plugin_name); #if defined(__MINGW32__) static const char plugin_ext[] = ".dll"; diff --git a/gcc/prefix.cc b/gcc/prefix.cc index 7ee59f74fc0..82ef3f26164 100644 --- a/gcc/prefix.cc +++ b/gcc/prefix.cc @@ -265,7 +265,7 @@ update_path (const char *path, const char *key) result = concat (key, &path[len], NULL); if (free_key) - free (CONST_CAST (char *, key)); + free (const_cast (key)); result = translate_name (result); } else diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc index 799fc06bd01..3cdbe46bd41 100644 --- a/gcc/pretty-print.cc +++ b/gcc/pretty-print.cc @@ -3055,7 +3055,7 @@ identifier_to_locale (const char *ident) /* Repeat the whole conversion process as needed with larger buffers so non-reversible transformations can always be detected. */ - ICONV_CONST char *inbuf = CONST_CAST (char *, ident); + ICONV_CONST char *inbuf = const_cast (ident); char *outbuf; size_t inbytesleft = idlen; size_t outbytesleft = ret_alloc - 1; diff --git a/gcc/selftest.cc b/gcc/selftest.cc index f7751174509..7f78effb0c1 100644 --- a/gcc/selftest.cc +++ b/gcc/selftest.cc @@ -80,7 +80,7 @@ print_diff (const location &loc, const char *val1, const char *val2) int exit_status = 0; int err = 0; pex_one (PEX_SEARCH | PEX_LAST, - args[0], CONST_CAST (char **, args), + args[0], const_cast (args), NULL, NULL, NULL, &exit_status, &err); } diff --git a/gcc/statistics.cc b/gcc/statistics.cc index e7c2c8d0a3b..9b3a36e0a98 100644 --- a/gcc/statistics.cc +++ b/gcc/statistics.cc @@ -74,7 +74,7 @@ stats_counter_hasher::equal (const statistics_counter *c1, inline void stats_counter_hasher::remove (statistics_counter *v) { - free (CONST_CAST (char *, v->id)); + free (const_cast (v->id)); free (v); } diff --git a/gcc/stringpool.cc b/gcc/stringpool.cc index 2d1eb4e2879..630b3e7c8cf 100644 --- a/gcc/stringpool.cc +++ b/gcc/stringpool.cc @@ -216,14 +216,14 @@ gt_pch_p_S (void *obj ATTRIBUTE_UNUSED, void *x ATTRIBUTE_UNUSED, void gt_pch_n_S (const void *x) { - gt_pch_note_object (CONST_CAST (void *, x), CONST_CAST (void *, x), + gt_pch_note_object (const_cast (x), const_cast (x), >_pch_p_S); } void gt_pch_n_S2 (const void *x, size_t string_len) { - gt_pch_note_object (CONST_CAST (void *, x), CONST_CAST (void *, x), + gt_pch_note_object (const_cast (x), const_cast (x), >_pch_p_S, string_len); } diff --git a/gcc/system.h b/gcc/system.h index faa6857690a..01fa005509a 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -1152,49 +1152,6 @@ extern void fancy_abort (const char *, int, const char *) #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. In some - cases we have non-const functions that return the argument - (e.g. next_nonnote_insn). Rather than create const shadow - functions, we can cast away const-ness in calling these interfaces - if we're careful to verify that the called function does indeed not - modify its argument and the return value is only used in a const - context. (This can be somewhat dangerous as these assumptions can - change after the fact). Beyond these uses, most other cases of - using this macro should be viewed with extreme caution. */ - -#ifdef __cplusplus -#define CONST_CAST2(TOTYPE,FROMTYPE,X) (const_cast (X)) -#else -#if defined(__GNUC__) && GCC_VERSION > 4000 -/* GCC 4.0.x has a bug where it may ICE on this expression, - so does GCC 3.4.x (PR17436). */ -#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq) -#elif defined(__GNUC__) -inline char * -helper_const_non_const_cast (const char *p) -{ - union { - const char *const_c; - char *c; - } val; - val.const_c = p; - return val.c; -} - -#define CONST_CAST2(TOTYPE,FROMTYPE,X) \ - ((TOTYPE) helper_const_non_const_cast ((const char *) (FROMTYPE) (X))) -#else -#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((TOTYPE)(FROMTYPE)(X)) -#endif -#endif -#define CONST_CAST(TYPE,X) CONST_CAST2 (TYPE, const TYPE, (X)) - /* Activate certain diagnostics as warnings (not errors via the -Werror flag). */ #if GCC_VERSION >= 4003 diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index 885716535f1..f2f160ae742 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -1242,7 +1242,7 @@ gimple_init_gcov_profiler (void) fn_name = concat ("__gcov_interval_profiler", fn_suffix, NULL); tree_interval_profiler_fn = build_fn_decl (fn_name, interval_profiler_fn_type); - free (CONST_CAST (char *, fn_name)); + free (const_cast (fn_name)); TREE_NOTHROW (tree_interval_profiler_fn) = 1; DECL_ATTRIBUTES (tree_interval_profiler_fn) = tree_cons (get_identifier ("leaf"), NULL, @@ -1255,7 +1255,7 @@ gimple_init_gcov_profiler (void) NULL_TREE); fn_name = concat ("__gcov_pow2_profiler", fn_suffix, NULL); tree_pow2_profiler_fn = build_fn_decl (fn_name, pow2_profiler_fn_type); - free (CONST_CAST (char *, fn_name)); + free (const_cast (fn_name)); TREE_NOTHROW (tree_pow2_profiler_fn) = 1; DECL_ATTRIBUTES (tree_pow2_profiler_fn) = tree_cons (get_identifier ("leaf"), NULL, @@ -1269,7 +1269,7 @@ gimple_init_gcov_profiler (void) fn_name = concat ("__gcov_topn_values_profiler", fn_suffix, NULL); tree_topn_values_profiler_fn = build_fn_decl (fn_name, topn_values_profiler_fn_type); - free (CONST_CAST (char *, fn_name)); + free (const_cast (fn_name)); TREE_NOTHROW (tree_topn_values_profiler_fn) = 1; DECL_ATTRIBUTES (tree_topn_values_profiler_fn) @@ -1287,7 +1287,7 @@ gimple_init_gcov_profiler (void) fn_name = concat ("__gcov_indirect_call_profiler_v4", fn_suffix, NULL); tree_indirect_call_profiler_fn = build_fn_decl (fn_name, ic_profiler_fn_type); - free (CONST_CAST (char *, fn_name)); + free (const_cast (fn_name)); TREE_NOTHROW (tree_indirect_call_profiler_fn) = 1; DECL_ATTRIBUTES (tree_indirect_call_profiler_fn) @@ -1311,14 +1311,14 @@ gimple_init_gcov_profiler (void) fn_name = concat ("__gcov_average_profiler", fn_suffix, NULL); tree_average_profiler_fn = build_fn_decl (fn_name, average_profiler_fn_type); - free (CONST_CAST (char *, fn_name)); + free (const_cast (fn_name)); TREE_NOTHROW (tree_average_profiler_fn) = 1; DECL_ATTRIBUTES (tree_average_profiler_fn) = tree_cons (get_identifier ("leaf"), NULL, DECL_ATTRIBUTES (tree_average_profiler_fn)); fn_name = concat ("__gcov_ior_profiler", fn_suffix, NULL); tree_ior_profiler_fn = build_fn_decl (fn_name, average_profiler_fn_type); - free (CONST_CAST (char *, fn_name)); + free (const_cast (fn_name)); TREE_NOTHROW (tree_ior_profiler_fn) = 1; DECL_ATTRIBUTES (tree_ior_profiler_fn) = tree_cons (get_identifier ("leaf"), NULL, diff --git a/gcc/tree.h b/gcc/tree.h index d650c85d5c5..49a443f74ed 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4279,7 +4279,7 @@ tree_vec_elt_check (const_tree __t, int __i, tree_check_failed (__t, __f, __l, __g, TREE_VEC, 0); if (__i < 0 || __i >= __t->base.u.length) tree_vec_elt_check_failed (__i, __t->base.u.length, __f, __l, __g); - return CONST_CAST (const_tree *, &__t->vec.a[__i]); + return const_cast (&__t->vec.a[__i]); //return &__t->vec.a[__i]; } @@ -4295,7 +4295,7 @@ omp_clause_elt_check (const_tree __t, int __i, tree_check_failed (__t, __f, __l, __g, OMP_CLAUSE, 0); if (__i < 0 || __i >= omp_clause_num_ops [__t->omp_clause.code]) omp_clause_operand_check_failed (__i, __t, __f, __l, __g); - return CONST_CAST (const_tree *, &__t->omp_clause.ops[__i]); + return const_cast (&__t->omp_clause.ops[__i]); } inline const_tree @@ -4353,7 +4353,7 @@ tree_operand_check (const_tree __t, int __i, const_tree __u = EXPR_CHECK (__t); if (__i < 0 || __i >= TREE_OPERAND_LENGTH (__u)) tree_operand_check_failed (__i, __u, __f, __l, __g); - return CONST_CAST (const_tree *, &__u->exp.operands[__i]); + return const_cast (&__u->exp.operands[__i]); } inline const_tree * @@ -4364,7 +4364,7 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i, tree_check_failed (__t, __f, __l, __g, __code, 0); if (__i < 0 || __i >= TREE_OPERAND_LENGTH (__t)) tree_operand_check_failed (__i, __t, __f, __l, __g); - return CONST_CAST (const_tree *, &__t->exp.operands[__i]); + return const_cast (&__t->exp.operands[__i]); } #endif diff --git a/gcc/tsystem.h b/gcc/tsystem.h index a33c92e41c6..9a93c030622 100644 --- a/gcc/tsystem.h +++ b/gcc/tsystem.h @@ -136,9 +136,6 @@ extern int errno; unreachable default case of a switch. Do not use gcc_assert(0). */ #define gcc_unreachable() (abort ()) -#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq) -#define CONST_CAST(TYPE,X) CONST_CAST2 (TYPE, const TYPE, (X)) - /* Filename handling macros. */ #include "filenames.h" diff --git a/gcc/vec.h b/gcc/vec.h index 7265c18c60f..0d4cffd0c3a 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -985,7 +985,7 @@ vec::iterate (unsigned ix, T **ptr) const { if (ix < m_vecpfx.m_num) { - *ptr = CONST_CAST (T *, &address ()[ix]); + *ptr = const_cast (&address ()[ix]); return true; } else