https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:b76d71564925abcabe6f5ad61d904b23c682cdfb commit r14-2433-gb76d71564925abcabe6f5ad61d904b23c682cdfb Author: Patrick Palka <ppa...@redhat.com> Date: Tue Jul 11 10:05:19 2023 -0400 c++: coercing variable template from current inst [PR110580] Here during ahead of time coercion of the variable template-id v1<int>, since we pass only the innermost arguments to coerce_template_parms (and outer arguments are still dependent at this point), substitution of the default template argument V=U just lowers U from level 2 to level 1 rather than replacing it with int as expected. Thus after coercion we incorrectly end up with (effectively) v1<int, T> instead of v1<int, int>. Coercion of a class/alias template-id on the other hand always passes all levels arguments, which avoids this issue. So this patch makes us do the same for variable template-ids. PR c++/110580 gcc/cp/ChangeLog: * pt.cc (lookup_template_variable): Pass all levels of arguments to coerce_template_parms, and use the parameters from the most general template. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ83.C: New test.