Bug 38950 - [4.3/4.4 regression] ICE: deducing function template arguments for array type.
Summary: [4.3/4.4 regression] ICE: deducing function template arguments for array type.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P2 normal
Target Milestone: 4.3.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code, rejects-valid
Depends on:
Blocks:
 
Reported: 2009-01-23 21:38 UTC by Johannes Schaub
Modified: 2009-02-17 18:27 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3.6 3.4.1
Known to fail: 3.4.2 4.2.0
Last reconfirmed: 2009-02-12 18:48:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Schaub 2009-01-23 21:38:17 UTC
The following snippet makes GCC 4.3.2 (and SVN versions as of 09/2008 still) cause an ICE:

template <typename T, T N> void f(T(&)[N]);

int main() {
    int x[2];
    unsigned int y[2];
    f(x); // works
    f(y); // ICE
}

Getting this output:

test.cpp: In function 'int main()':
test.cpp:7: internal compiler error: in dependent_type_p, at cp/pt.c:15585

More information about this issue: http://stackoverflow.com/questions/472530/how-to-pass-an-array-size-as-a-template-with-template-type
Comment 1 Wolfgang Bangerth 2009-01-30 15:27:15 UTC
Confirmed. This used to work in 4.1 where we got the following error
(which does not earn the prize for the prettiest error message ever):

g/x> /home/bangerth/bin/gcc-4.1.1/bin/c++ -c x.cc
x.cc: In function 'int main()':
x.cc:7: error: size of array has non-integral type 'T'
x.cc:1: error: size of array has non-integral type 'T'
x.cc:1: error: size of array has non-integral type 'T'
x.cc:7: error: invalid initialization of reference of type 'unsigned int (&)[1]' from expression of type 'unsigned int [2]'
x.cc:1: error: in passing argument 1 of 'void f(T (&)[N]) [with T = unsigned int, T N = ((T)2)]'
x.cc: In function 'void f(T (&)[N]) [with T = unsigned int, T N = ((T)2)]':
x.cc:7:   instantiated from here
x.cc:1: error: size of array has non-integral type 'T'
Comment 2 Wolfgang Bangerth 2009-01-30 15:28:21 UTC
Thinking some more about it, I believe that the code is actually valid.
icc accepts it, for comparison.

W.
Comment 3 Richard Biener 2009-02-01 13:25:03 UTC
3.3.6 and 3.4.1 accept it, starting with 3.4.2 we reject it and since 4.2.0 we ICE.
Comment 4 Johannes Schaub 2009-02-03 02:02:55 UTC
Yes, sorry for not mentioning it. I also think the code is valid. In the link to stackoverflow.com, where i answered that guys question, i gave reasons why i think so. Next time i will put what i think about that directly into the bugreport :)
Comment 5 Jason Merrill 2009-02-12 22:40:51 UTC
Subject: Bug 38950

Author: jason
Date: Thu Feb 12 22:40:37 2009
New Revision: 144139

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144139
Log:
        PR c++/38950
        * pt.c (unify)[TEMPLATE_PARM_INDEX]: Convert to the tsubsted type.

Added:
    trunk/gcc/testsuite/g++.dg/template/array20.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Jason Merrill 2009-02-17 18:27:45 UTC
Subject: Bug 38950

Author: jason
Date: Tue Feb 17 18:27:32 2009
New Revision: 144239

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144239
Log:
        PR c++/38950
        * pt.c (unify)[TEMPLATE_PARM_INDEX]: Convert to the tsubsted type.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/g++.dg/template/array20.C
      - copied unchanged from r144139, trunk/gcc/testsuite/g++.dg/template/array20.C
Modified:
    branches/gcc-4_3-branch/gcc/cp/ChangeLog
    branches/gcc-4_3-branch/gcc/cp/pt.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 7 Jason Merrill 2009-02-17 18:27:48 UTC
Fixed.