aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2009-04-21 19:49:23 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2009-04-21 19:49:23 +0000
commit36ef72625cd8bc38933adf8c06a7de4f093e98c6 (patch)
tree252a0939bdbc3eeb3a8ea24b01705c79fcc71cfe /gcc/cp
parentad41bd84ff7298f2eff1d0b99e1975f99bc8ba68 (diff)
downloadgcc-36ef72625cd8bc38933adf8c06a7de4f093e98c6.zip
gcc-36ef72625cd8bc38933adf8c06a7de4f093e98c6.tar.gz
gcc-36ef72625cd8bc38933adf8c06a7de4f093e98c6.tar.bz2
re PR c++/35711 (bad text in -Wcast-qual warning (forgets volatile))
2009-04-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR c++/35711 cp/ * typeck.c (check_for_casting_away_constness): We diagnose casting away any qualifiers not just constness. (casts_away_constness): Mention that it handles more than just constness. testsuite/ * g++.dg/warn/pr35711.C: New. * g++.dg/conversion/ptrmem2.C: Update. From-SVN: r146537
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/typeck.c56
2 files changed, 42 insertions, 22 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5bca4b4..99c7826 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2009-04-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ PR c++/35711
+ * typeck.c (check_for_casting_away_constness): We diagnose casting
+ away any qualifiers not just constness.
+ (casts_away_constness): Mention that it handles more than just
+ constness.
+
2009-04-21 Joseph Myers <joseph@codesourcery.com>
* ChangeLog, ChangeLog-1993, ChangeLog-1994, ChangeLog-1995,
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 9084b5e..34a20b8 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5038,7 +5038,12 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
}
/* Issue a diagnostic message if casting from SRC_TYPE to DEST_TYPE
- casts away constness. CAST gives the type of cast. */
+ casts away constness. CAST gives the type of cast.
+
+ ??? This function warns for casting away any qualifier not just
+ const. We would like to specify exactly what qualifiers are casted
+ away.
+*/
static void
check_for_casting_away_constness (tree src_type, tree dest_type,
@@ -5049,27 +5054,29 @@ check_for_casting_away_constness (tree src_type, tree dest_type,
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",
+ if (!casts_away_constness (src_type, dest_type))
+ return;
+
+ switch (cast)
+ {
+ case CAST_EXPR:
+ warning (OPT_Wcast_qual,
+ "cast from type %qT to type %qT casts away qualifiers",
src_type, dest_type);
- return;
- default:
- gcc_unreachable();
- }
+ return;
+
+ case STATIC_CAST_EXPR:
+ error ("static_cast from type %qT to type %qT casts away qualifiers",
+ src_type, dest_type);
+ return;
+
+ case REINTERPRET_CAST_EXPR:
+ error ("reinterpret_cast from type %qT to type %qT casts away qualifiers",
+ src_type, dest_type);
+ return;
+ default:
+ gcc_unreachable();
+ }
}
/* Convert EXPR (an expression with pointer-to-member type) to TYPE
@@ -7362,7 +7369,12 @@ casts_away_constness_r (tree *t1, tree *t2)
}
/* Returns nonzero if casting from TYPE1 to TYPE2 casts away
- constness. */
+ constness.
+
+ ??? This function returns non-zero if casting away qualifiers not
+ just const. We would like to return to the caller exactly which
+ qualifiers are casted away to give more accurate diagnostics.
+*/
static bool
casts_away_constness (tree t1, tree t2)