aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/pt.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-02-28 15:05:30 -0500
committerPatrick Palka <ppalka@redhat.com>2023-02-28 15:05:30 -0500
commitd3d205ab440886164b6de2be2a2efa10cac95b66 (patch)
tree5ed37246db4303d50f761537d738fc751b2c5e6f /gcc/cp/pt.cc
parentafe6cea4489846aa8585f3c045d16cdaa08cc6cd (diff)
downloadgcc-d3d205ab440886164b6de2be2a2efa10cac95b66.zip
gcc-d3d205ab440886164b6de2be2a2efa10cac95b66.tar.gz
gcc-d3d205ab440886164b6de2be2a2efa10cac95b66.tar.bz2
c++: non-dependent variable template-id [PR108848]
Here we're treating deeming the non-dependent variable template-id tag<int> as dependent ever since r226642 gave variable TEMPLATE_ID_EXPR an empty type, which causes the call to finish_template_variable from finish_id_expression_1 to be unreachable at template parse time. Thus we're led into thinking tag<int>.var<void> refers to a dependent name. This patch fixes this by making finish_id_expression_1 instantiate a variable template-id as long as it's not dependent according to the dependence test in lookup_and_finish_template_variable rather than according to type_dependent_expression_p. PR c++/108848 gcc/cp/ChangeLog: * pt.cc (finish_template_variable): Move dependence check to here from ... (lookup_and_finish_template_variable): ... here. * semantics.cc (finish_id_expression_1): Call finish_template_variable sooner, before (and regardless of) the type_dependent_expression_p test. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/noexcept1.C: Don't expect a bogus "different exception specifier" error. Expect a separate "not usable in a constant expression" error. * g++.dg/cpp1y/var-templ75.C: New test. * g++.dg/cpp1y/var-templ76.C: New test.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r--gcc/cp/pt.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index f636bac..03958da 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10317,7 +10317,8 @@ lookup_template_variable (tree templ, tree arglist)
return build2 (TEMPLATE_ID_EXPR, NULL_TREE, templ, arglist);
}
-/* Instantiate a variable declaration from a TEMPLATE_ID_EXPR for use. */
+/* Instantiate a variable declaration from a TEMPLATE_ID_EXPR if it's
+ not dependent. */
tree
finish_template_variable (tree var, tsubst_flags_t complain)
@@ -10325,6 +10326,12 @@ finish_template_variable (tree var, tsubst_flags_t complain)
tree templ = TREE_OPERAND (var, 0);
tree arglist = TREE_OPERAND (var, 1);
+ /* If the template or arguments are dependent, then we
+ can't resolve the TEMPLATE_ID_EXPR yet. */
+ if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (templ)) != 1
+ || any_dependent_template_arguments_p (arglist))
+ return var;
+
tree parms = DECL_TEMPLATE_PARMS (templ);
arglist = coerce_template_parms (parms, arglist, templ, complain);
if (arglist == error_mark_node)
@@ -10352,19 +10359,14 @@ lookup_and_finish_template_variable (tree templ, tree targs,
tsubst_flags_t complain)
{
tree var = lookup_template_variable (templ, targs);
- if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (templ)) == 1
- && !any_dependent_template_arguments_p (targs))
- {
- /* We may be called while doing a partial substitution, but the
- type of the variable template may be auto, in which case we
- will call do_auto_deduction in mark_used (which clears tf_partial)
- and the auto must be properly reduced at that time for the
- deduction to work. */
- complain &= ~tf_partial;
- var = finish_template_variable (var, complain);
- mark_used (var);
- }
-
+ /* We may be called while doing a partial substitution, but the
+ type of the variable template may be auto, in which case we
+ will call do_auto_deduction in mark_used (which clears tf_partial)
+ and the auto must be properly reduced at that time for the
+ deduction to work. */
+ complain &= ~tf_partial;
+ var = finish_template_variable (var, complain);
+ mark_used (var);
return convert_from_reference (var);
}