diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-15 17:52:34 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-15 17:52:34 +0000 |
commit | e3fc42824b556433d483f7ff3e8635ea0b5df8aa (patch) | |
tree | e55cf621262bd8905304880523a1cf0e0b671073 | |
parent | 5619747e763aff61b269f6f1ebc593fc42d2b446 (diff) | |
download | ppe42-gcc-e3fc42824b556433d483f7ff3e8635ea0b5df8aa.tar.gz ppe42-gcc-e3fc42824b556433d483f7ff3e8635ea0b5df8aa.zip |
PR c++/24667
* typeck.c (check_for_casting_away_constness): Use the diag_fn.
(build_const_cast_1): Call it, for C-style casts.
PR c++/24667
* g++.dg/warn/Wcast-qual1.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107032 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wcast-qual1.C | 7 |
4 files changed, 32 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 60f3166b3ce..c42ef5ca769 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2005-11-15 Mark Mitchell <mark@codesourcery.com> + + PR c++/24667 + * typeck.c (check_for_casting_away_constness): Use the diag_fn. + (build_const_cast_1): Call it, for C-style casts. + 2005-11-14 Mark Mitchell <mark@codesourcery.com> PR c++/24687 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 31e2d6f58fc..a86ee6a516e 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4559,8 +4559,8 @@ check_for_casting_away_constness (tree src_type, tree dest_type, const char *description) { if (diag_fn && casts_away_constness (src_type, dest_type)) - error ("%s from type %qT to type %qT casts away constness", - description, src_type, dest_type); + diag_fn ("%s from type %qT to type %qT casts away constness", + description, src_type, dest_type); } /* Convert EXPR (an expression with pointer-to-member type) to TYPE @@ -5085,9 +5085,9 @@ build_reinterpret_cast (tree type, tree expr) /* Perform a const_cast from EXPR to TYPE. If the cast is valid, return an appropriate expression. Otherwise, return error_mark_node. If the cast is not valid, and COMPLAIN is true, - then a diagnostic will be issued. If VALID_P is non-NULL, its - value upon return will indicate whether or not the conversion - succeeded. */ + then a diagnostic will be issued. If VALID_P is non-NULL, we are + performing a C-style cast, its value upon return will indicate + whether or not the conversion succeeded. */ static tree build_const_cast_1 (tree dst_type, tree expr, bool complain, @@ -5163,7 +5163,15 @@ build_const_cast_1 (tree dst_type, tree expr, bool complain, && comp_ptr_ttypes_const (dst_type, src_type)) { if (valid_p) - *valid_p = true; + { + *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"); + } if (reference_type) { expr = build_unary_op (ADDR_EXPR, expr, 0); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9ae49db6c9..26d56c3cbda 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-11-15 Mark Mitchell <mark@codesourcery.com> + + PR c++/24667 + * g++.dg/warn/Wcast-qual1.C: New test. + 2005-11-15 Jan Hubicka <jh@suse.cz> * gcc.dg/winline-5.c: Add large-unit-insns limit. diff --git a/gcc/testsuite/g++.dg/warn/Wcast-qual1.C b/gcc/testsuite/g++.dg/warn/Wcast-qual1.C new file mode 100644 index 00000000000..e6ad4f6a06d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wcast-qual1.C @@ -0,0 +1,7 @@ +// PR c++/24667 +// { dg-options "-Wcast-qual" } + +int main(int, char**) { + const int foo[2] = {1,1}; + ((int*)foo)[0] = 0; // { dg-warning "cast" } +} |