[Bug c++/59761] New: ICE: g++ segfaults in test case involving constexpr default constructor with uninitialized member and template type alias
mizvekov at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Jan 10 17:37:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59761
Bug ID: 59761
Summary: ICE: g++ segfaults in test case involving constexpr
default constructor with uninitialized member and
template type alias
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mizvekov at gmail dot com
Created attachment 31803
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31803&action=edit
ICE/segfault when compiling this
Compiling the attached test_bad.cc with g++ results in an ICE, with the
following message:
test_bad.cc: In substitution of ‘template<bool B> using enable_if_t = typename
std::enable_if<B>::type [with bool B = is_foo0((*(const foo<0>*)(&
foo<0>())))]’:
test_bad.cc:12:22: required from here
test_bad.cc:12:22: internal compiler error: Segmentation fault
template<typename T, class = enable_if_t< is_foo0(T{}) >> int test() { return
0; }
^
This error only happens when both using the enable_if_t template type alias,
and struct foo having a data member uninitialized by the constexpr default
constructor.
If enable_if_t<...> is substituted by std::enable_if<...>::type, as in the
attached file test_good1.cc, then g++ rejects the code without any ICE. The
following is output:
test_good1.cc:12:36: error: no matching function for call to ‘test()’
static const int fi = test<foo<0>>();
^
test_good1.cc:12:36: note: candidate is:
test_good1.cc:10:80: note: template<class T, class> int test()
template<typename T, class = typename std::enable_if< is_foo0(T{})>::type> int
test() { return 0; }
^
test_good1.cc:10:80: note: template argument deduction/substitution failed:
test_good1.cc:10:22: error: ‘constexpr foo<X>::foo() [with int X = 0]’ called
in a constant expression
template<typename T, class = typename std::enable_if< is_foo0(T{})>::type> int
test() { return 0; }
^
test_good1.cc:4:12: note: ‘constexpr foo<X>::foo() [with int X = 0]’ is not
usable as a constexpr function because:
constexpr foo() {}
^
test_good1.cc:4:12: error: uninitialized member ‘foo<0>::bar’ in ‘constexpr’
constructor
test_good1.cc:10:22: note: in template argument for type ‘bool’
template<typename T, class = typename std::enable_if< is_foo0(T{})>::type> int
test() { return 0; }
^
If the code is modified so the default constructor leaves no members
uninitialized, as in the attached file test_good2.cc, then g++ accepts the
code.
Note that clang 3.4 quietly accepts all three versions, even with -Wall.
This is the version of g++ where the problem was found:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-4.8-20131219/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-cloog-backend=isl --disable-cloog-version-check --enable-lto
--enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu
--disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 4.8.2 20131219 (prerelease) (GCC)
More information about the Gcc-bugs
mailing list