summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-11-02 18:04:48 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2011-11-02 18:04:48 +0000
commit609cab98a1445d1297053e842d0799dbe02e532c (patch)
tree90c45f83ea3800ead15ab39e98c2fc820e041ece
parent5a24323785f5a217f850ef10bdc96a98ea084741 (diff)
downloadgcc-609cab98a1445d1297053e842d0799dbe02e532c.tar.gz
2011-11-02 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50956 * builtins.c (fold_builtin_memchr): Fix cast. /cp 2011-11-02 Paolo Carlini <paolo.carlini@oracle.com> PR c++/50956 * typeck.c (build_const_cast_1): Fix -Wcast-qual for false comp_ptr_ttypes_const. /testsuite 2011-11-02 Paolo Carlini <paolo.carlini@oracle.com> PR c++/50956 * g++.dg/warn/Wcast-qual2.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@180786 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/builtins.c2
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c57
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/warn/Wcast-qual2.C4
6 files changed, 53 insertions, 26 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 70ae866463f..fe07de1b70f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2011-11-02 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/50956
+ * builtins.c (fold_builtin_memchr): Fix cast.
+
2011-11-02 Teresa Johnson <tejohnson@google.com>
* config/i386/predicates.md (promotable_binary_operator): Add minus
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 51d7b12e687..bad31659a83 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -8427,7 +8427,7 @@ fold_builtin_memchr (location_t loc, tree arg1, tree arg2, tree len, tree type)
if (target_char_cast (arg2, &c))
return NULL_TREE;
- r = (char *) memchr (p1, c, tree_low_cst (len, 1));
+ r = (const char *) memchr (p1, c, tree_low_cst (len, 1));
if (r == NULL)
return build_int_cst (TREE_TYPE (arg1), 0);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d246e5cc4ba..90651e6e540 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2011-11-02 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/50956
+ * typeck.c (build_const_cast_1): Fix -Wcast-qual for false
+ comp_ptr_ttypes_const.
+
2011-11-02 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* Make-lang.in (g++spec.o): Pass SHLIB instead of SHLIB_LINK.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 8d70df5eb75..0b1f217a908 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6345,34 +6345,41 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain,
return error_mark_node;
}
- if ((TYPE_PTR_P (src_type) || TYPE_PTRMEM_P (src_type))
- && comp_ptr_ttypes_const (dst_type, src_type))
+ if (TYPE_PTR_P (src_type) || TYPE_PTRMEM_P (src_type))
{
- if (valid_p)
- {
- *valid_p = true;
- /* This cast is actually a C-style cast. Issue a warning if
- the user is making a potentially unsafe cast. */
- check_for_casting_away_constness (src_type, dst_type, CAST_EXPR,
- complain);
- }
- if (reference_type)
+ if (comp_ptr_ttypes_const (dst_type, src_type))
{
- expr = cp_build_addr_expr (expr, complain);
- expr = build_nop (reference_type, expr);
- return convert_from_reference (expr);
- }
- else
- {
- expr = decay_conversion (expr);
- /* build_c_cast puts on a NOP_EXPR to make the result not an
- lvalue. Strip such NOP_EXPRs if VALUE is being used in
- non-lvalue context. */
- if (TREE_CODE (expr) == NOP_EXPR
- && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
- expr = TREE_OPERAND (expr, 0);
- return build_nop (dst_type, expr);
+ if (valid_p)
+ {
+ *valid_p = true;
+ /* This cast is actually a C-style cast. Issue a warning if
+ the user is making a potentially unsafe cast. */
+ check_for_casting_away_constness (src_type, dst_type,
+ CAST_EXPR, complain);
+ }
+ if (reference_type)
+ {
+ expr = cp_build_addr_expr (expr, complain);
+ expr = build_nop (reference_type, expr);
+ return convert_from_reference (expr);
+ }
+ else
+ {
+ expr = decay_conversion (expr);
+ /* build_c_cast puts on a NOP_EXPR to make the result not an
+ lvalue. Strip such NOP_EXPRs if VALUE is being used in
+ non-lvalue context. */
+ if (TREE_CODE (expr) == NOP_EXPR
+ && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
+ expr = TREE_OPERAND (expr, 0);
+ return build_nop (dst_type, expr);
+ }
}
+ else if (valid_p
+ && !at_least_as_qualified_p (TREE_TYPE (dst_type),
+ TREE_TYPE (src_type)))
+ check_for_casting_away_constness (src_type, dst_type, CAST_EXPR,
+ complain);
}
if (complain & tf_error)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 057fd7c5973..aae9e361144 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-11-02 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/50956
+ * g++.dg/warn/Wcast-qual2.C: New.
+
2011-11-02 Tom de Vries <tom@codesourcery.com>
PR tree-optimization/50763
diff --git a/gcc/testsuite/g++.dg/warn/Wcast-qual2.C b/gcc/testsuite/g++.dg/warn/Wcast-qual2.C
new file mode 100644
index 00000000000..23dbb4d39b0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wcast-qual2.C
@@ -0,0 +1,4 @@
+// PR c++/50956
+// { dg-options "-Wcast-qual" }
+
+void* p = (void*)"txt"; // { dg-warning "cast" }