typeck.c (check_for_casting_away_constness): Use 1 single argument, the type of cast, to decide what diagnostics generate.
2008-02-23 Manuel Lopez-Ibanez <manu@gcc.gnu.org> * typeck.c (check_for_casting_away_constness): Use 1 single argument, the type of cast, to decide what diagnostics generate. (build_static_cast_1): Remove unused code. Update call to check_for_casting_away_constness. (build_reinterpret_cast_1): Update call to check_for_casting_away_constness. (build_const_cast_1): Likewise. From-SVN: r132609
This commit is contained in:
parent
55092ebf6e
commit
86b7b98bed
2 changed files with 43 additions and 35 deletions
|
@ -1,3 +1,13 @@
|
|||
2008-02-23 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
|
||||
|
||||
* typeck.c (check_for_casting_away_constness): Use 1 single
|
||||
argument, the type of cast, to decide what diagnostics generate.
|
||||
(build_static_cast_1): Remove unused code. Update call to
|
||||
check_for_casting_away_constness.
|
||||
(build_reinterpret_cast_1): Update call to
|
||||
check_for_casting_away_constness.
|
||||
(build_const_cast_1): Likewise.
|
||||
|
||||
2008-02-24 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* error.c (dump_expr): Don't deal directly with NEW_EXPR (and
|
||||
|
|
|
@ -4842,18 +4842,38 @@ build_compound_expr (tree lhs, tree rhs)
|
|||
}
|
||||
|
||||
/* Issue a diagnostic message if casting from SRC_TYPE to DEST_TYPE
|
||||
casts away constness. DIAG_FN gives the function to call if we
|
||||
need to issue a diagnostic; if it is NULL, no diagnostic will be
|
||||
issued. DESCRIPTION explains what operation is taking place. */
|
||||
casts away constness. CAST gives the type of cast. */
|
||||
|
||||
static void
|
||||
check_for_casting_away_constness (tree src_type, tree dest_type,
|
||||
void (*diag_fn)(const char *, ...) ATTRIBUTE_GCC_CXXDIAG(1,2),
|
||||
const char *description)
|
||||
enum tree_code cast)
|
||||
{
|
||||
if (diag_fn && casts_away_constness (src_type, dest_type))
|
||||
diag_fn ("%s from type %qT to type %qT casts away constness",
|
||||
description, src_type, dest_type);
|
||||
/* C-style casts are allowed to cast away constness. With
|
||||
WARN_CAST_QUAL, we still want to issue a warning. */
|
||||
if (cast == CAST_EXPR && !warn_cast_qual)
|
||||
return;
|
||||
|
||||
if (casts_away_constness (src_type, dest_type))
|
||||
switch (cast)
|
||||
{
|
||||
case CAST_EXPR:
|
||||
warning (OPT_Wcast_qual,
|
||||
"cast from type %qT to type %qT casts away constness",
|
||||
src_type, dest_type);
|
||||
return;
|
||||
|
||||
case STATIC_CAST_EXPR:
|
||||
error ("static_cast from type %qT to type %qT casts away constness",
|
||||
src_type, dest_type);
|
||||
return;
|
||||
|
||||
case REINTERPRET_CAST_EXPR:
|
||||
error ("reinterpret_cast from type %qT to type %qT casts away constness",
|
||||
src_type, dest_type);
|
||||
return;
|
||||
default:
|
||||
gcc_unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert EXPR (an expression with pointer-to-member type) to TYPE
|
||||
|
@ -4939,8 +4959,6 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
|
|||
tree intype;
|
||||
tree result;
|
||||
tree orig;
|
||||
void (*diag_fn)(const char*, ...) ATTRIBUTE_GCC_CXXDIAG(1,2);
|
||||
const char *desc;
|
||||
|
||||
/* Assume the cast is valid. */
|
||||
*valid_p = true;
|
||||
|
@ -4950,21 +4968,6 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
|
|||
/* Save casted types in the function's used types hash table. */
|
||||
used_types_insert (type);
|
||||
|
||||
/* Determine what to do when casting away constness. */
|
||||
if (c_cast_p)
|
||||
{
|
||||
/* C-style casts are allowed to cast away constness. With
|
||||
WARN_CAST_QUAL, we still want to issue a warning. */
|
||||
diag_fn = warn_cast_qual ? warning0 : NULL;
|
||||
desc = "cast";
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A static_cast may not cast away constness. */
|
||||
diag_fn = error;
|
||||
desc = "static_cast";
|
||||
}
|
||||
|
||||
/* [expr.static.cast]
|
||||
|
||||
An lvalue of type "cv1 B", where B is a class type, can be cast
|
||||
|
@ -5089,7 +5092,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
|
|||
tree base;
|
||||
|
||||
if (!c_cast_p)
|
||||
check_for_casting_away_constness (intype, type, diag_fn, desc);
|
||||
check_for_casting_away_constness (intype, type, STATIC_CAST_EXPR);
|
||||
base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
|
||||
c_cast_p ? ba_unique : ba_check,
|
||||
NULL);
|
||||
|
@ -5124,8 +5127,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
|
|||
if (can_convert (t1, t2) || can_convert (t2, t1))
|
||||
{
|
||||
if (!c_cast_p)
|
||||
check_for_casting_away_constness (intype, type, diag_fn,
|
||||
desc);
|
||||
check_for_casting_away_constness (intype, type, STATIC_CAST_EXPR);
|
||||
return convert_ptrmem (type, expr, /*allow_inverse_p=*/1,
|
||||
c_cast_p);
|
||||
}
|
||||
|
@ -5142,7 +5144,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
|
|||
&& TYPE_PTROB_P (type))
|
||||
{
|
||||
if (!c_cast_p)
|
||||
check_for_casting_away_constness (intype, type, diag_fn, desc);
|
||||
check_for_casting_away_constness (intype, type, STATIC_CAST_EXPR);
|
||||
return build_nop (type, expr);
|
||||
}
|
||||
|
||||
|
@ -5327,8 +5329,7 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
|
|||
tree sexpr = expr;
|
||||
|
||||
if (!c_cast_p)
|
||||
check_for_casting_away_constness (intype, type, error,
|
||||
"reinterpret_cast");
|
||||
check_for_casting_away_constness (intype, type, REINTERPRET_CAST_EXPR);
|
||||
/* Warn about possible alignment problems. */
|
||||
if (STRICT_ALIGNMENT && warn_cast_align
|
||||
&& !VOID_TYPE_P (type)
|
||||
|
@ -5483,10 +5484,7 @@ build_const_cast_1 (tree dst_type, tree expr, bool complain,
|
|||
*valid_p = true;
|
||||
/* This cast is actually a C-style cast. Issue a warning if
|
||||
the user is making a potentially unsafe cast. */
|
||||
if (warn_cast_qual)
|
||||
check_for_casting_away_constness (src_type, dst_type,
|
||||
warning0,
|
||||
"cast");
|
||||
check_for_casting_away_constness (src_type, dst_type, CAST_EXPR);
|
||||
}
|
||||
if (reference_type)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue