Bug 84489 - [6/7 Regression] Non-type template parameter dependency
Summary: [6/7 Regression] Non-type template parameter dependency
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.3.0
: P2 normal
Target Milestone: 8.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-02-20 17:35 UTC by Vincent Reverdy
Modified: 2018-03-23 22:04 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.4.0, 8.0
Known to fail: 6.4.0, 7.3.0
Last reconfirmed: 2018-02-21 00:00:00


Attachments
Example code of the bug (139 bytes, text/x-csrc)
2018-02-20 17:35 UTC, Vincent Reverdy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Reverdy 2018-02-20 17:35:52 UTC
Created attachment 43475 [details]
Example code of the bug

Consider the following code in C++11.
=========================================================
#include <iostream>

template <class T = int, T N = T(), T B = (N >> 1)>
constexpr T f0() {return 0;}

template <class T = int, T N = T(), bool B = (N >> 1)>
constexpr T f1() {return 0;}

int main()
{
    f0(); // No bug
    f1(); // Bug here
    return 0;
}
=========================================================

It compiles well under g++ 4.7, 4.8, 4.9, 5.X but fails to compile under 6.X and 7.X. It also compiles well under clang. The returned error is:

=========================================================
gcc_bug_template_bool.cpp: In function 'int main()':
gcc_bug_template_bool.cpp:12:8: error: no matching function for call to 'f1()'
     f1();
        ^
gcc_bug_template_bool.cpp:7:13: note: candidate: template<class T, T N, bool B> constexpr T f1()
 constexpr T f1() {return 0;}
             ^~
gcc_bug_template_bool.cpp:7:13: note:   template argument deduction/substitution failed:
gcc_bug_template_bool.cpp:6:49: error: invalid use of template type parameter 'T'
 template <class T = int, T N = T(), bool B = (N >> 1)>
                                              ~~~^~~~~
gcc_bug_template_bool.cpp:6:53: error: could not convert template argument '<expression error>' from '<type error>' to 'bool'
 template <class T = int, T N = T(), bool B = (N >> 1)>
=========================================================
Comment 1 Martin Sebor 2018-02-21 21:34:19 UTC
The error is present with with the top of trunk.  The first revision that fails to compile the code is r223301 (gcc 6.0.0).  It refers to DR 1391 but I'm not sure that the DR has a bearing on whether the test case is valid.  Other compilers including Clang, EDG, Intel ICC, and MSVC, successfully compile the code so I'll confirm this report as valid on that basis.

r223301 | jason | 2015-05-18 13:14:11 -0400 (Mon, 18 May 2015) | 3 lines

	DR 1391
	* pt.c (type_unification_real): Check convertibility here.
	(unify_one_argument): Not here.
Comment 2 Jason Merrill 2018-02-27 17:27:18 UTC
Author: jason
Date: Tue Feb 27 17:26:47 2018
New Revision: 258039

URL: https://gcc.gnu.org/viewcvs?rev=258039&root=gcc&view=rev
Log:
	PR c++/84489 - dependent default template argument

	* pt.c (type_unification_real): Handle early substitution failure.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 3 Jason Merrill 2018-02-27 21:42:22 UTC
Fixed on trunk so far.
Comment 4 Jason Merrill 2018-03-02 16:56:21 UTC
Author: jason
Date: Fri Mar  2 16:55:49 2018
New Revision: 258144

URL: https://gcc.gnu.org/viewcvs?rev=258144&root=gcc&view=rev
Log:
	PR c++/84489 - dependent default template argument

	* pt.c (type_unification_real): Handle early substitution failure.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/pt.c
Comment 5 Jason Merrill 2018-03-02 18:25:20 UTC
Author: jason
Date: Fri Mar  2 18:24:40 2018
New Revision: 258152

URL: https://gcc.gnu.org/viewcvs?rev=258152&root=gcc&view=rev
Log:
	PR c++/84489 - dependent default template argument

	* pt.c (type_unification_real): Handle early substitution failure.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/pt.c
Comment 6 Jason Merrill 2018-03-02 20:22:57 UTC
Fixed.
Comment 7 Jonathan Wakely 2018-03-23 12:22:45 UTC
This caused a regression for the reproducer in PR 78489 comment 2
Comment 8 Jason Merrill 2018-03-23 12:57:42 UTC
Author: jason
Date: Fri Mar 23 12:57:09 2018
New Revision: 258802

URL: https://gcc.gnu.org/viewcvs?rev=258802&root=gcc&view=rev
Log:
	PR c++/78489 - Substitution in wrong order

	PR c++/84489
	* pt.c (type_unification_real): Revert last two changes.

Removed:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/alias-decl-63.C
    branches/gcc-6-branch/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/pt.c
Comment 9 Jason Merrill 2018-03-23 14:40:48 UTC
Author: jason
Date: Fri Mar 23 14:40:06 2018
New Revision: 258814

URL: https://gcc.gnu.org/viewcvs?rev=258814&root=gcc&view=rev
Log:
	PR c++/78489 - Substitution in wrong order

	PR c++/84489
	* pt.c (type_unification_real): Revert last two changes.

Added:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/sfinae60.C
Removed:
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/alias-decl-63.C
    branches/gcc-7-branch/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg7.C
Modified:
    branches/gcc-7-branch/gcc/cp/ChangeLog
    branches/gcc-7-branch/gcc/cp/pt.c
Comment 10 Jason Merrill 2018-03-23 14:54:51 UTC
Only fixed for GCC 8 now, as the fix has proved too unstable for earlier releases.
Comment 11 Jason Merrill 2018-03-23 22:04:23 UTC
Author: jason
Date: Fri Mar 23 22:03:51 2018
New Revision: 258824

URL: https://gcc.gnu.org/viewcvs?rev=258824&root=gcc&view=rev
Log:
	PR c++/78489 - wrong SFINAE behavior.

	PR c++/84489
	* pt.c (type_unification_real): Don't defer substitution failure.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg4a.C
    trunk/gcc/testsuite/g++.dg/cpp0x/sfinae60.C
    trunk/gcc/testsuite/g++.dg/cpp0x/sfinae61.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c