diff mbox

[c++] : Fix PR/53904

Message ID CAEwic4aCTB+Ty4MTjC58FTRu=knzJYGA7-TUbgJSVp5HQthupA@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Nov. 26, 2014, 5:52 p.m. UTC
Ok.  Adjusted patch attached.  Nevertheless we should use here
unsigned HWI instead of possible truncation to signed int.  I admit
that it is unlikely to have more then 2^31 elements, but well ....

Ok for apply with adjusted ChangeLog?

Regards,
Kai

Comments

Jason Merrill Nov. 26, 2014, 6:30 p.m. UTC | #1
OK, thanks.

Jason
H.J. Lu Nov. 27, 2014, 8:17 p.m. UTC | #2
On Wed, Nov 26, 2014 at 9:52 AM, Kai Tietz <ktietz70@googlemail.com> wrote:
> Ok.  Adjusted patch attached.  Nevertheless we should use here
> unsigned HWI instead of possible truncation to signed int.  I admit
> that it is unlikely to have more then 2^31 elements, but well ....
>
> Ok for apply with adjusted ChangeLog?
>
> Regards,
> Kai
>

On Linux/x86, the testcase fails with

output is:
/export/gnu/import/git/gcc/gcc/testsuite/g++.dg/cpp0x/pr63904.C: In
instantiation of 'struct foo<0>':^M
/export/gnu/import/git/gcc/gcc/testsuite/g++.dg/cpp0x/pr63904.C:10:26:
  required from here^M
/export/gnu/import/git/gcc/gcc/testsuite/g++.dg/cpp0x/pr63904.C:6:12:
error: ISO C++ forbids zero-size array [-Wpedantic]^M

FAIL: g++.dg/cpp0x/pr63904.C  -std=c++11 (test for excess errors)

H.J.
Kai Tietz Nov. 27, 2014, 8:50 p.m. UTC | #3
Sorry, missed to add needed hunk to disable pedantic warnings for this testcase.
Committed it as obvious fix at rev 218130.

Kai
diff mbox

Patch

Index: constexpr.c
===================================================================
--- constexpr.c (Revision 218076)
+++ constexpr.c (Arbeitskopie)
@@ -2013,12 +2013,12 @@  cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tre
                     bool *non_constant_p, bool *overflow_p)
 {
   tree elttype = TREE_TYPE (atype);
-  int max = tree_to_shwi (array_type_nelts (atype));
+  unsigned HOST_WIDE_INT max = tree_to_uhwi (array_type_nelts_top (atype));
   verify_ctor_sanity (ctx, atype);
   vec<constructor_elt, va_gc> **p = &CONSTRUCTOR_ELTS (ctx->ctor);
   vec_alloc (*p, max + 1);
   bool pre_init = false;
-  int i;
+  unsigned HOST_WIDE_INT i;

   /* For the default constructor, build up a call to the default
      constructor of the element type.  We only need to handle class types
@@ -2043,7 +2043,7 @@  cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tre
       pre_init = true;
     }

-  for (i = 0; i <= max; ++i)
+  for (i = 0; i < max; ++i)
     {
       tree idx = build_int_cst (size_type_node, i);
       tree eltinit;