Bug 59044 - [4.8/4.9 Regression] Internal compiler error triggers when accessing a typedef in a specialized member class
Summary: [4.8/4.9 Regression] Internal compiler error triggers when accessing a typede...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P2 normal
Target Milestone: 4.8.3
Assignee: Jason Merrill
URL:
Keywords:
: 58518 59052 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-11-08 00:41 UTC by Tom De Caluwé
Modified: 2014-01-03 03:30 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-11-08 00:00:00


Attachments
Preprocessor output (244 bytes, text/plain)
2013-11-08 00:41 UTC, Tom De Caluwé
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom De Caluwé 2013-11-08 00:41:23 UTC
Created attachment 31180 [details]
Preprocessor output

The following code triggers an internal compiler error when compiled with 'g++ bug.cpp' (the complete preprocessed file can be found in the attachment):

/* ---- bug.cpp --------------------------------------- */
template <class T>
class C {
private:
    template <T a, T b>
    struct Implementation;
    template <T b>
    struct Implementation<0, b> { typedef void Typedef; };
public:
    typedef typename Implementation<0, 0>::Typedef Type;
};

template class C<unsigned>;
/* ---------------------------------------------------- */

The error message produced by g++ 4.8.1 (as found in the g++-4.8 package in the Ubuntu 13.10 repo, see below for build information):

bug.cpp: In instantiation of ‘class C<unsigned int>’:
bug.cpp:12:16:   required from here
bug.cpp:9:52: internal compiler error: in tsubst, at cp/pt.c:11313
     typedef typename Implementation<0, 0>::Typedef Type;
                                                    ^

This bug is still present in the gcc-snapshot package. However the code compiles fine in g++ 4.7.3 (as found in the g++-4.7 package).

Additional information:

GCC version: gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8) 
System type: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.1-10ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --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.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-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 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Comment 1 Paolo Carlini 2013-11-08 09:45:45 UTC
The code may be invalid however.
Comment 2 Tom De Caluwé 2013-11-08 15:01:21 UTC
As far as I can verify partial specializations are only allowed at namespace scope so you're right. However gcc never used to complain about such constructs.

In any case, an internal compiler error is never desired behaviour, hence the bug report.
Comment 3 Paolo Carlini 2013-11-08 15:19:22 UTC
Yes. It's all about prioritizing, an ICE on invalid isn't the same as an ICE on valid, even if it's a regression.
Comment 4 Tom De Caluwé 2013-11-08 15:32:56 UTC
However the following code seems to be valid but results in the same ICE:

/* ---- bug.cpp --------------------------------------- */
namespace N {

template <class T>
class C {
private:
    template <T a, T b>
    struct Implementation {};
public:
    typedef typename Implementation<0, 0>::Typedef Type;
};

template <class T>
template <T b>
struct C<T>::Implementation<0, b> { typedef void Typedef; };

}

template class N::C<unsigned>;
/* ---------------------------------------------------- */
Comment 5 Paolo Carlini 2013-11-08 15:38:34 UTC
Frankly, I'm not sure either, current clang rejects it the same way, for example. In any case, in Bugzilla we have got at least 2/3 on valid Bugs triggering that gcc_assert, hopefully will be fixed all together.
Comment 6 Tom De Caluwé 2013-11-08 17:12:29 UTC
I reported a related bug with valid code which does not trigger this ICE (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59052).

Also LLVM bug 16519 (http://llvm.org/bugs/show_bug.cgi?id=16519) might be related to the errors triggered by clang when compiling the example code above. The example code provided in bug 59052 does compile with clang.
Comment 7 Jason Merrill 2013-12-05 19:15:10 UTC
*** Bug 59052 has been marked as a duplicate of this bug. ***
Comment 8 Jason Merrill 2013-12-05 22:46:38 UTC
Author: jason
Date: Thu Dec  5 22:46:36 2013
New Revision: 205720

URL: http://gcc.gnu.org/viewcvs?rev=205720&root=gcc&view=rev
Log:
	PR c++/59044
	PR c++/59052
	* pt.c (most_specialized_class): Use the partially instantiated
	template for deduction.  Drop the TMPL parameter.

Added:
    trunk/gcc/testsuite/g++.dg/template/partial14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 9 Jason Merrill 2013-12-05 23:28:28 UTC
Author: jason
Date: Thu Dec  5 23:28:25 2013
New Revision: 205723

URL: http://gcc.gnu.org/viewcvs?rev=205723&root=gcc&view=rev
Log:
	PR c++/59044
	PR c++/59052
	* pt.c (most_specialized_class): Use the partially instantiated
	template for deduction.  Drop the TMPL parameter.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/template/partial14.C
Modified:
    branches/gcc-4_8-branch/gcc/cp/ChangeLog
    branches/gcc-4_8-branch/gcc/cp/pt.c
Comment 10 Volker Reichelt 2013-12-06 23:52:19 UTC
*** Bug 58518 has been marked as a duplicate of this bug. ***
Comment 11 Jason Merrill 2014-01-03 03:30:34 UTC
Fixed for 4.8.3.