Bug 55724 - [4.7/4.8 Regression] [C++11] Default type of a template value is not working
Summary: [4.7/4.8 Regression] [C++11] Default type of a template value is not working
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 4.7.3
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-12-17 19:08 UTC by Vincent
Modified: 2012-12-20 02:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.3, 4.6.3
Known to fail: 4.7.2, 4.8.0
Last reconfirmed: 2012-12-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent 2012-12-17 19:08:36 UTC
The following code does not compile with g++ 4.7 :

--------------------------------------------
template<int N> struct S {};
template<typename T = int, T N> void f(S<N>) {}
int main() { S<1> s; f(s); }
--------------------------------------------

(source : http://stackoverflow.com/q/13915835/882932)
Comment 1 Ed Catmur 2012-12-17 19:25:39 UTC
It's not entirely clear in the standard, but my understanding of 14.8.2p5 is that default template argument substitution is contemporaneous to template argument deduction for any particular parameter.  Non-type template parameter types deduced from preceding arguments *are* accepted by gcc:

template<int N> struct S {};
template<typename T, T N> void g(T, S<N>) {}
int main() { S<1> s; g(2, s); }
Comment 2 Richard Biener 2012-12-18 15:08:44 UTC
trunk now says:

t.C: In function 'int main()':
t.C:3:25: error: no matching function for call to 'f(S<1>&)'
 int main() { S<1> s; f(s); }
                         ^
t.C:3:25: note: candidate is:
t.C:2:38: note: template<class T, T N> void f(S<N>)
 template<typename T = int, T N> void f(S<N>) {}
                                      ^
t.C:2:38: note:   template argument deduction/substitution failed:
t.C:3:25: note:   couldn't deduce template parameter 'N'
 int main() { S<1> s; f(s); }
                         ^
Comment 3 Jason Merrill 2012-12-19 22:22:42 UTC
Author: jason
Date: Wed Dec 19 22:22:36 2012
New Revision: 194620

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194620
Log:
	PR c++/55724
	* pt.c (type_unification_real): Re-combine post-deduction loops.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 4 Jason Merrill 2012-12-20 02:58:20 UTC
Author: jason
Date: Thu Dec 20 02:58:16 2012
New Revision: 194627

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194627
Log:
	PR c++/55724
	* pt.c (type_unification_real): Re-combine post-deduction loops.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg4.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/pt.c
Comment 5 Jason Merrill 2012-12-20 02:59:55 UTC
Fixed.