Created attachment 33994 [details] Preprocessed source The following code causes an internal compiler error: template<int N> struct foo { constexpr foo() : a() {} int a[N]; }; int main() { foo< (foo<1>{}).a[0] > f; } constexpr-initalization.cpp:7:25: in constexpr expansion of ‘f.foo<N>::foo<0>()’ constexpr-initalization.cpp:7:25: internal compiler error: in tree_low_cst, at tree.h:4849 foo< (foo<1>{}).a[0] > f;
It seems to be related to constexpr.c:cxx_eval_vec_init_1 function. The line ' int max = tree_to_shwi (array_type_nelts (atype));' there should be changed into 'int max = (int) tree_to_uhwi (array_type_nelts (atype));'. Issue is that array_type_netls returns size_type node (which is unsigned) with UHWI_MAX as value. Means that on conversions the value won't fit into shwi. By reading value as unsigned and then later on casting it to signed (btw shouldn't we use here instead HOST_WIDE_INT?), we solve this issue.
Author: ktietz Date: Thu Nov 27 12:56:58 2014 New Revision: 218122 URL: https://gcc.gnu.org/viewcvs?rev=218122&root=gcc&view=rev Log: PR c++/63904 * g++.dg/cpp0x/pr63904.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/pr63904.C Modified: trunk/gcc/testsuite/ChangeLog
Author: ktietz Date: Thu Nov 27 13:02:45 2014 New Revision: 218123 URL: https://gcc.gnu.org/viewcvs?rev=218123&root=gcc&view=rev Log: 2014-11-27 Kai Tietz <ktietz@redhat.com> PR c++/63904 * constexpr.c (cxx_eval_vec_init_1): Avoid type-overflow issue. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/constexpr.c
So fixed.