aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2008-02-25 01:39:14 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2008-02-25 01:39:14 +0000
commit86b7b98bed5f98614829dda72e7d2b69b90cf396 (patch)
tree4ba9990311686c3b71c6b79b6aecf6c760b8c610 /gcc
parent55092ebf6e03abd80d72cd10937f9cfa9d4de64e (diff)
downloadgcc-86b7b98bed5f98614829dda72e7d2b69b90cf396.zip
gcc-86b7b98bed5f98614829dda72e7d2b69b90cf396.tar.gz
gcc-86b7b98bed5f98614829dda72e7d2b69b90cf396.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/typeck.c68
2 files changed, 43 insertions, 35 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d4d726c..f7fba35 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index eef6914..81fbe77 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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)
{