Bug 48132 - [4.6/4.7 Regression] [C++0x] Internal compiler error on array of std::complex with -std=c++0x
Summary: [4.6/4.7 Regression] [C++0x] Internal compiler error on array of std::complex...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2011-03-15 08:37 UTC by Martin Kronbichler
Modified: 2011-03-16 20:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-03-15 08:59:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Kronbichler 2011-03-15 08:37:29 UTC
gcc 4.6.0 weekly snapshot 20110312

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --libexecdir=/usr/lib --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --without-included-gettext --enable-threads=posix --program-suffix=-4.6 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=core2 --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-cpu=core2
Thread model: posix
gcc version 4.6.0 20110312 (experimental) (GCC)

With the following code:

#include <complex>
void test () {
  std::complex<double> array[] = { std::complex<double>(0,1) };
}

I get:
$ g++ -std=c++0x  -c complex_test.cc -o complex_test.o
complex_test.cc: In function ‘void test()’:
complex_test.cc:4:62: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.

The code compiles fine without -std=c++0x, and it is also fine with gcc 4.5.2.
Comment 1 Jonathan Wakely 2011-03-15 08:59:36 UTC
confirmed
Comment 2 Jakub Jelinek 2011-03-15 12:15:13 UTC
Reduced testcase:

struct C
{
  constexpr C (int x) : c (x) {}
  int c;
};

void
foo ()
{
  C a[] = { C (0) };
}
Comment 3 Jakub Jelinek 2011-03-15 13:19:09 UTC
Regressed (expectedly) with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166167
The problem seems to be that the middle-end relies on indexes being filled in in ctors for arrays, but the C++ FE in this case doesn't fill them in.
For POD arrays the indexes are added by process_init_constructor_array, but that
isn't called in this case (both because check_initializer will do:
              /* Don't call digest_init; it's unnecessary and will complain
                 about aggregate initialization of non-aggregate classes.  */
              flags |= LOOKUP_ALREADY_DIGESTED;
and also because it is called only for:
  if (BRACE_ENCLOSED_INITIALIZER_P (init)
      && !TYPE_NON_AGGREGATE_CLASS (type))
    return process_init_constructor (type, init);
Comment 4 Jason Merrill 2011-03-16 20:03:17 UTC
Author: jason
Date: Wed Mar 16 20:03:12 2011
New Revision: 171065

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171065
Log:
	PR c++/48132
	* decl.c (check_array_designated_initializer): Allow integer index.
	(reshape_init_array_1): Set index on the elements.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-array3.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/decl.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 5 Jason Merrill 2011-03-16 20:04:13 UTC
Author: jason
Date: Wed Mar 16 20:04:06 2011
New Revision: 171068

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171068
Log:
	PR c++/48132
	* decl.c (check_array_designated_initializer): Allow integer index.
	(reshape_init_array_1): Set index on the elements.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-array3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jason Merrill 2011-03-16 20:22:16 UTC
Fixed.