diff options
author | Patrick Palka <ppalka@redhat.com> | 2021-09-16 15:03:55 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2021-09-16 15:03:55 -0400 |
commit | 2e2e65a46d2674bed53afd211493876ee2b79453 (patch) | |
tree | 1fe2b9a3a2b42eee9d88b3cc4738e866e1c87fb7 /gcc/cp/constraint.cc | |
parent | cfea7b86f2430b9cb8018379b071f4004233119c (diff) | |
download | gcc-2e2e65a46d2674bed53afd211493876ee2b79453.zip gcc-2e2e65a46d2674bed53afd211493876ee2b79453.tar.gz gcc-2e2e65a46d2674bed53afd211493876ee2b79453.tar.bz2 |
c++: constrained variable template issues [PR98486]
This fixes some issues with constrained variable templates:
- Constraints aren't checked when explicitly specializing a variable
template.
- Constraints aren't attached to a static data member template at
parse time.
- Constraints don't get propagated when (partially) instantiating a
static data member template, so we need to make sure to look up
constraints using the most general template during satisfaction.
PR c++/98486
gcc/cp/ChangeLog:
* constraint.cc (get_normalized_constraints_from_decl): Always
look up constraints using the most general template.
* decl.c (grokdeclarator): Set constraints on a static data
member template.
* pt.c (determine_specialization): Check constraints on a
variable template.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-var-templ1.C: New test.
* g++.dg/cpp2a/concepts-var-templ1a.C: New test.
* g++.dg/cpp2a/concepts-var-templ1b.C: New test.
Diffstat (limited to 'gcc/cp/constraint.cc')
-rw-r--r-- | gcc/cp/constraint.cc | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 1aaf1e2..2896efd 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -918,20 +918,22 @@ get_normalized_constraints_from_decl (tree d, bool diag = false) tmpl = most_general_template (tmpl); } + d = tmpl ? tmpl : decl; + /* If we're not diagnosing errors, use cached constraints, if any. */ if (!diag) - if (tree *p = hash_map_safe_get (normalized_map, tmpl)) + if (tree *p = hash_map_safe_get (normalized_map, d)) return *p; tree norm = NULL_TREE; - if (tree ci = get_constraints (decl)) + if (tree ci = get_constraints (d)) { push_access_scope_guard pas (decl); norm = get_normalized_constraints_from_info (ci, tmpl, diag); } if (!diag) - hash_map_safe_put<hm_ggc> (normalized_map, tmpl, norm); + hash_map_safe_put<hm_ggc> (normalized_map, d, norm); return norm; } |