On 10/21/2011 04:56 PM, Jason Merrill wrote:
I think the fix for 35602 was wrong; instead of trying to suppress the
warning, we should avoid building expressions that trip it. In this
case, the problem is a type mismatch in build_vec_init between
maxindex/iterator (ptrdiff_type_node) and array_type_nelts_total
(sizetype). And indeed, converting (ptrdiff_t)-1 to unsigned changes
its sign.
I think a better fix for 35602 would be to bail out of build_vec_init
exit early if maxindex is -1.
Ah great, thanks a lot. The below passes testing, if it's Ok I would be
tempted to backport it to the 4_6-branch too after 4.6.2 is out..
Thanks again,
Paolo.
//////////////////////
/cp
2011-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/45385
* init.c (build_vec_init): Early return error_mark_node if
maxindex is -1.
/c-family
2011-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/45385
* c-common.c (conversion_warning): Remove code looking for
artificial operands.
/testsuite
2011-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/45385
* g++.dg/warn/Wconversion4.C: New.
Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c (revision 180307)
+++ c-family/c-common.c (working copy)
@@ -2121,23 +2121,12 @@ unsafe_conversion_p (tree type, tree expr, bool pr
static void
conversion_warning (tree type, tree expr)
{
- int i;
- const int expr_num_operands = TREE_OPERAND_LENGTH (expr);
tree expr_type = TREE_TYPE (expr);
location_t loc = EXPR_LOC_OR_HERE (expr);
if (!warn_conversion && !warn_sign_conversion)
return;
- /* If any operand is artificial, then this expression was generated
- by the compiler and we do not warn. */
- for (i = 0; i < expr_num_operands; i++)
- {
- tree op = TREE_OPERAND (expr, i);
- if (op && DECL_P (op) && DECL_ARTIFICIAL (op))
- return;
- }
-
switch (TREE_CODE (expr))
{
case EQ_EXPR:
Index: testsuite/g++.dg/warn/Wconversion4.C
===================================================================
--- testsuite/g++.dg/warn/Wconversion4.C (revision 0)
+++ testsuite/g++.dg/warn/Wconversion4.C (revision 0)
@@ -0,0 +1,17 @@
+// PR c++/45385
+// { dg-options "-Wconversion" }
+
+void foo(unsigned char);
+
+class Test
+{
+ void eval()
+ {
+ foo(bar()); // { dg-warning "may alter its value" }
+ }
+
+ unsigned int bar() const
+ {
+ return __INT_MAX__ * 2U + 1;
+ }
+};
Index: cp/init.c
===================================================================
--- cp/init.c (revision 180307)
+++ cp/init.c (working copy)
@@ -2998,7 +2998,8 @@ build_vec_init (tree base, tree maxindex, tree ini
if (TREE_CODE (atype) == ARRAY_TYPE && TYPE_DOMAIN (atype))
maxindex = array_type_nelts (atype);
- if (maxindex == NULL_TREE || maxindex == error_mark_node)
+ if (maxindex == NULL_TREE || maxindex == error_mark_node
+ || tree_int_cst_equal (maxindex, integer_minus_one_node))
return error_mark_node;
if (explicit_value_init_p)