re PR c++/50956 (-Wcast-qual does not work)
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. From-SVN: r180786
This commit is contained in:
parent
742e5233b8
commit
2d4e2a688e
6 changed files with 53 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
if (comp_ptr_ttypes_const (dst_type, src_type))
|
||||
{
|
||||
*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);
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
4
gcc/testsuite/g++.dg/warn/Wcast-qual2.C
Normal file
4
gcc/testsuite/g++.dg/warn/Wcast-qual2.C
Normal file
|
@ -0,0 +1,4 @@
|
|||
// PR c++/50956
|
||||
// { dg-options "-Wcast-qual" }
|
||||
|
||||
void* p = (void*)"txt"; // { dg-warning "cast" }
|
Loading…
Add table
Reference in a new issue