demo code: struct foo_t { template<class T> static constexpr bool bar = true; }; inline constexpr foo_t foo{}; template<class T> struct baz { static_assert(foo.bar<T>); // bug in clang (before instantiation) and gcc (during instantiation) static_assert(foo_t::bar<T>); // OK }; int main() { static_assert(foo.bar<void>, ""); // OK static_assert(foo_t::bar<void>, ""); // OK static_cast<void>(baz<void>{}); }
Tried --- gcc/cp/pt.c.jj 2020-07-27 10:38:19.000000000 +0200 +++ gcc/cp/pt.c 2020-07-27 17:25:09.748240198 +0200 @@ -16838,14 +16838,17 @@ tsubst_copy (tree t, tree args, tsubst_f case TEMPLATE_ID_EXPR: { /* Substituted template arguments */ - tree fn = TREE_OPERAND (t, 0); + tree expr = TREE_OPERAND (t, 0); tree targs = TREE_OPERAND (t, 1); - fn = tsubst_copy (fn, args, complain, in_decl); + expr = tsubst_copy (expr, args, complain, in_decl); if (targs) targs = tsubst_template_args (targs, args, complain, in_decl); - return lookup_template_function (fn, targs); + if (variable_template_p (expr)) + return lookup_and_finish_template_variable (expr, targs, complain); + else + return lookup_template_function (expr, targs); } case TREE_LIST: but that just means an ICE elsewhere.
(In reply to Jakub Jelinek from comment #1) > Tried > --- gcc/cp/pt.c.jj 2020-07-27 10:38:19.000000000 +0200 > +++ gcc/cp/pt.c 2020-07-27 17:25:09.748240198 +0200 > @@ -16838,14 +16838,17 @@ tsubst_copy (tree t, tree args, tsubst_f > case TEMPLATE_ID_EXPR: > { > /* Substituted template arguments */ > - tree fn = TREE_OPERAND (t, 0); > + tree expr = TREE_OPERAND (t, 0); > tree targs = TREE_OPERAND (t, 1); > > - fn = tsubst_copy (fn, args, complain, in_decl); > + expr = tsubst_copy (expr, args, complain, in_decl); > if (targs) > targs = tsubst_template_args (targs, args, complain, in_decl); > > - return lookup_template_function (fn, targs); > + if (variable_template_p (expr)) > + return lookup_and_finish_template_variable (expr, targs, complain); > + else > + return lookup_template_function (expr, targs); > } > > case TREE_LIST: > but that just means an ICE elsewhere. Hmm, seems using lookup_template_variable instead of lookup_and_finish_template_variable works.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:574e7601829733d7cae20b5dc7034b876cc76b30 commit r11-7541-g574e7601829733d7cae20b5dc7034b876cc76b30 Author: Patrick Palka <ppalka@redhat.com> Date: Sat Mar 6 00:07:43 2021 -0500 c++: Fix tsubsting member variable template-id [PR96330] This makes tsubst_copy appropriately handle a variable template-id, which in turn fixes tsubsting a COMPONENT_REF whose member operand is known at parse time to be a variable template-id, as in the initialization of 'x' in the first testcase. Previously, we rejected this testcase with the error "foo_t::bar<T> is not a function template", issued from lookup_template_fuction. We were already properly handling the analagous case where the object operand of the COMPONENT_REF is dependent (and so the member operand is a dependent template name), but there doesn't seems to be existing test coverage for this, hence the second testcase below. gcc/cp/ChangeLog: PR c++/96330 * pt.c (tsubst_copy) <case TEMPLATE_ID_EXPR>: Rename local variable 'fn' to 'tmpl'. Handle a variable template-id by calling lookup_template_variable. gcc/testsuite/ChangeLog: PR c++/96330 * g++.dg/cpp1y/var-templ68.C: New test. * g++.dg/cpp1y/var-templ68a.C: New test. Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Fixed for GCC 11. Thanks for the bug report!