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)> =========================================================
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.
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
Fixed on trunk so far.
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
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
Fixed.
This caused a regression for the reproducer in PR 78489 comment 2
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
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
Only fixed for GCC 8 now, as the fix has proved too unstable for earlier releases.
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