Bug 50473 - [C++0x] ICE in type_has_nontrivial_copy_init, at cp/tree.c:2574
Summary: [C++0x] ICE in type_has_nontrivial_copy_init, at cp/tree.c:2574
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 5.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2011-09-21 13:05 UTC by Yuhki Ogasawara
Modified: 2014-11-17 20:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-09-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuhki Ogasawara 2011-09-21 13:05:10 UTC
ICE occured.

Codes (a.cpp):

template<unsigned N>
struct s
{};

template<class... Ts>
constexpr s<sizeof...(Ts)> f()
{
 return {};
}

template<class T>
struct test
{
 static constexpr auto&& value = f();
};

int main(){}


Compile error messages:

$ g++4.7 -std=c++0x -Wall -Wextra -pedantic a.cpp
a.cpp:14:36: internal compiler error: in type_has_nontrivial_copy_init, at cp/tree.c:2574
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


Vesion info:

$ g++4.7 -v
Built by Equation Solution <http://www.Equation.com>.
Using built-in specs.
COLLECT_GCC=C:\cygwin\home\RiSK\misc\gcc4.7\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/cygwin/home/risk/misc/gcc4.7/bin/../libexec/gcc/i686-pc-mingw32/4.7.0/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ../gcc-4.7-20110917-mingw/configure --host=i686-pc-mingw32 --build=x86_64-unknown-linux-gnu --target
=i686-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.7-20110917 --with-gcc --with-gnu
-as --with-gnu-ld --with-host-libstdcxx='-lstdc++ -lsupc++ -lm' --with-ppl=/home/gfortran/gcc-home/binary/mingw32/nat
ive/x86_32/ppl --with-cloog=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/cloog --with-gmp=/home/gfortran/gcc-
home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr --with-mp
c=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpc --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cros
s/x86_32/gcc/4.7-20110917 --disable-shared --disable-nls --disable-tls --disable-win32-registry --enable-libquadmath-
support --enable-libquadmath --enable-languages=c,c++,fortran --enable-libgomp --enable-threads=win32 --enable-lto --
enable-static --enable-shared=lto-plugin --enable-plugins --enable-ld=yes --enable-cloog-backend=ppl
Thread model: win32
gcc version 4.7.0 20110917 (experimental) (GCC)
Comment 1 Paolo Carlini 2011-10-17 10:53:44 UTC
Jason, the call chain here is set_up_extended_ref_temp -> get_target_expr -> get_target_expr_sfinae -> build_target_expr_with_type -> type_has_nontrivial_copy_init, which hits gcc_assert (COMPLETE_TYPE_P (t)).

Looks like tweaking, eg, build_target_expr_with_type, to check for the offending situation and return error_mark_node avoids the ICE, but I don't know at the moment if something deeper is actually going on...
Comment 2 Paolo Carlini 2011-11-11 01:38:40 UTC
Apparently r181278 doesn't ICE anymore:

50473.C:14:36: error: taking address of temporary [-fpermissive]
50473.C:14:36: error: ‘* & s<0u>()’ is not a constant expression

but the error message seems anyway pretty obscure and actually I don't see why the test is invalid. Jason, can you help triaging this?
Comment 3 Paolo Carlini 2011-11-11 10:13:16 UTC
The rvalue reference is essential. With this we still ICE:

constexpr int f() { return 1; }

template<class T>
struct test
{
  static constexpr auto&& value = f();
};
Comment 4 Jason Merrill 2011-11-11 21:27:08 UTC
Yep, the problem seems to be that we built up trees in the template that we don't then want to tsubst.
Comment 5 Jason Merrill 2014-11-17 20:18:28 UTC
Author: jason
Date: Mon Nov 17 20:17:56 2014
New Revision: 217672

URL: https://gcc.gnu.org/viewcvs?rev=217672&root=gcc&view=rev
Log:
	PR c++/50473
	* decl.c (cp_finish_decl): Don't try to process a non-dependent
	constant initializer for a reference.
	* pt.c (value_dependent_expression_p): A reference is always
	dependent.
	* call.c (extend_ref_init_temps_1): Also clear TREE_SIDE_EFFECTS
	on any NOP_EXPRs.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-ref5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-ice12.C
Comment 6 Jason Merrill 2014-11-17 20:21:47 UTC
Fixed for GCC 5.