[4.9/4.10 Regression] ICE when static_cast from constexpr in specialization of template-class

Bug #1314182 reported by Deniz Bahadir
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Unknown
Unknown
gcc-4.9 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

The associated upstream bug-report can be found at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60999

'lsb_release -rd' :
Description: Ubuntu 14.04 LTS
Release: 14.04

'apt-cache policy pkgname':
gcc-4.9:
  Installiert: 4.9-20140406-1ubuntu1
  Installationskandidat: 4.9-20140406-1ubuntu1
  Versionstabelle:
 *** 4.9-20140406-1ubuntu1 0
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/ trusty/main amd64 Packages
        100 /var/lib/dpkg/status

For completion I copy the content of the upstream bug-report here, too:

The following code produces an internal compiler error (ICE) in GCC 4.9, but did compile fine in GCC 4.8:

<code>

  // general template
  template <typename A>
  struct foo
  {
  };

  // template specialization
  template<>
  struct foo<int>
  {
      static constexpr int code = 42;
      unsigned int bar = static_cast<unsigned int>(code);
      // ICE at static_cast during instantiation. --^
  };

  // instantiation
  foo<int> a;

</code>

Compiling with the following line (using GCC 4.9) reproduced the ICE:
  g++ -Wall -Wextra -std=c++11 -c ICE.cpp

The output of 'g++ -v -save-temps -Wall -Wextra -std=c++11 -c ICE.cpp' yields the following information:

Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9-20140406-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.0 20140405 (experimental) [trunk revision 209157] (Ubuntu 4.9-20140406-1ubuntu1)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-std=c++11' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE ICE.cpp -mtune=generic -march=x86-64 -std=c++11 -Wall -Wextra -fpch-preprocess -fstack-protector -Wformat -Wformat-security -o ICE.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.9"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.9
 /usr/include/x86_64-linux-gnu/c++/4.9
 /usr/include/c++/4.9/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-std=c++11' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/cc1plus -fpreprocessed ICE.ii -quiet -dumpbase ICE.cpp -mtune=generic -march=x86-64 -auxbase ICE -Wall -Wextra -std=c++11 -version -fstack-protector -Wformat -Wformat-security -o ICE.s
GNU C++ (Ubuntu 4.9-20140406-1ubuntu1) version 4.9.0 20140405 (experimental) [trunk revision 209157] (x86_64-linux-gnu)
 compiled by GNU C version 4.9.0 20140405 (experimental) [trunk revision 209157], GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Ubuntu 4.9-20140406-1ubuntu1) version 4.9.0 20140405 (experimental) [trunk revision 209157] (x86_64-linux-gnu)
 compiled by GNU C version 4.9.0 20140405 (experimental) [trunk revision 209157], GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 6752b609dd6385b31002233d89fe2356
ICE.cpp:17:10: in constexpr expansion of ‘a.foo<int>::foo()’
ICE.cpp:17:10: internal compiler error: unexpected expression ‘static_cast<unsigned int>(foo<int>::code)’ of kind static_cast_expr
 foo<int> a;
          ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.9/README.Bugs> for instructions.
Preprocessed source stored into /tmp/cc5DJH1d.out file, please attach this to your bugreport.

Tags: c++11
Revision history for this message
Deniz Bahadir (bagira80) wrote :
Revision history for this message
Deniz Bahadir (bagira80) wrote :
Deniz Bahadir (bagira80)
summary: - [4.9 Regression] ICE when static_cast from constexpr in specialization
- of template-class
+ [4.9/4.10 Regression] ICE when static_cast from constexpr in
+ specialization of template-class
Revision history for this message
Deniz Bahadir (bagira80) wrote :

Fixed upstream.

Changed in gcc-4.9 (Ubuntu):
status: New → Fix Committed
Revision history for this message
Matthias Klose (doko) wrote :

fixed in utopic

Changed in gcc-4.9 (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.