GCC 9.1 fails to compile the following code (previous versions compile it just fine). === test.cpp === template <class T> struct S { template <class U, class V> static void foo(V) { } void bar() { foo<void>(1); } }; === === Console === ~/tmp$ g++-9.1.0 -c test.cpp test.cpp: In member function ‘void S<T>::bar()’: test.cpp:11:20: error: no matching function for call to ‘S<T>::foo<void>(int)’ 11 | foo<void>(1); | ^ test.cpp:5:17: note: candidate: ‘template<class T> template<class U, class V> static void S<T>::foo(V)’ 5 | static void foo(V) | ^~~ test.cpp:5:17: note: template argument deduction/substitution failed: test.cpp:11:20: note: mismatched types ‘V’ and ‘int’ 11 | foo<void>(1); | === === Compiler version === ~/tmp$ g++-9.1.0 -v Using built-in specs. COLLECT_GCC=g++-9.1.0 COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-9.1.0/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --prefix=/home/brd/soft/gcc-9.1.0 Thread model: posix gcc version 9.1.0 (GCC) ===
Started with r265734.
Mine then.
Seems to be caused by this change: @@ -16327,15 +16388,6 @@ cp_parser_template_name (cp_parser* parser, } } - /* If DECL is dependent, and refers to a function, then just return - its name; we will look it up again during template instantiation. */ - if (DECL_FUNCTION_TEMPLATE_P (decl) || !DECL_P (decl)) - { - tree scope = ovl_scope (decl); - if (TYPE_P (scope) && dependent_type_p (scope)) - return identifier; - } - return decl; }
GCC 9.2 has been released.
*** Bug 91479 has been marked as a duplicate of this bug. ***
Test from 91479: template <class T> struct foo { template <typename U, typename=void> static void bar(const U&) {} static void bar(int x) { bar<int>(x); } };
*** Bug 92221 has been marked as a duplicate of this bug. ***
Test from Bug 92221: template <typename> class a { using b = int; using c = int; b d; void e() { g<c>(d); } template <typename... f> static void g(f...); };
Finally posted a patch: https://gcc.gnu.org/ml/gcc-patches/2020-03/msg00181.html
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:6b3302da9ef26aa11940f8c0dc92bec19e15c09b commit r10-7007-g6b3302da9ef26aa11940f8c0dc92bec19e15c09b Author: Marek Polacek <polacek@redhat.com> Date: Tue Mar 3 17:56:44 2020 -0500 c++: Fix mismatch in template argument deduction [PR90505] My GCC 9 patch for C++20 P0846R0 (ADL and function templates) tweaked cp_parser_template_name to only return an identifier if name lookup didn't find anything. In the deduce4.C case it means that we now return an OVERLOAD. That means that cp_parser_template_id will call lookup_template_function whereby producing a TEMPLATE_ID_EXPR with unknown_type_node. Previously, we created a TEMPLATE_ID_EXPR with no type, making it type-dependent. What we have now is no longer type-dependent. And so, when we call finish_call_expr after we've parsed "foo<int>(10)", even though we're in a template, we still do the normal processing, thus perform overload resolution. When adding the template candidate foo we need to deduce the template arguments, and that is where things go downhill. When fn_type_unification sees that we have explicit template arguments, but they aren't complete, it will use them to substitute the function type. So we substitute e.g. "void <T33d> (U)". But the explicit template argument was for a different parameter so we don't actually substitute anything. But the problem here was that we reduced the template level of 'U' anyway. So then when we're actually deducing the template arguments via type_unification_real, we fail in unify: 22932 if (TEMPLATE_TYPE_LEVEL (parm) 22933 != template_decl_level (tparm)) 22934 /* The PARM is not one we're trying to unify. Just check 22935 to see if it matches ARG. */ because 'parm' has been reduced but 'tparm' has not yet. Therefore we shouldn't reduce the template level of template parameters when tf_partial aka template argument deduction substitution. But we can only return after performing the cp_build_qualified_type etc. business otherwise things break horribly. 2020-03-03 Jason Merrill <jason@redhat.com> Marek Polacek <polacek@redhat.com> PR c++/90505 - mismatch in template argument deduction. * pt.c (tsubst): Don't reduce the template level of template parameters when tf_partial. * g++.dg/template/deduce4.C: New test. * g++.dg/template/deduce5.C: New test. * g++.dg/template/deduce6.C: New test. * g++.dg/template/deduce7.C: New test.
Fixed on trunk so far.
The releases/gcc-9 branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:581825efc30ce79d86dfb0ebf378913fdec44adf commit r9-8333-g581825efc30ce79d86dfb0ebf378913fdec44adf Author: Marek Polacek <polacek@redhat.com> Date: Wed Mar 4 18:49:37 2020 -0500 c++: Fix mismatch in template argument deduction [PR90505] 2020-03-03 Jason Merrill <jason@redhat.com> Marek Polacek <polacek@redhat.com> PR c++/90505 - mismatch in template argument deduction. * pt.c (tsubst): Don't reduce the template level of template parameters when tf_partial. * g++.dg/template/deduce4.C: New test. * g++.dg/template/deduce5.C: New test. * g++.dg/template/deduce6.C: New test. * g++.dg/template/deduce7.C: New test.
Fixed.