aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-07-12 16:35:18 -0400
committerPatrick Palka <ppalka@redhat.com>2021-07-12 16:35:18 -0400
commit8d75b8830e9dafb4e0c400c723653512adf40295 (patch)
treefcd8164e8bbbd2e9178ac9e7eae0035372eb2bfe /gcc/cp/decl.c
parent8d980e84240c82502661758fbecd5f456018ea89 (diff)
downloadgcc-8d75b8830e9dafb4e0c400c723653512adf40295.zip
gcc-8d75b8830e9dafb4e0c400c723653512adf40295.tar.gz
gcc-8d75b8830e9dafb4e0c400c723653512adf40295.tar.bz2
c++: permit deduction guides at class scope [PR79501]
This adds support for declaring (class-scope) deduction guides for a member class template. Fortunately it seems only a couple of changes are needed in order for the existing CTAD machinery to handle them properly: we need to make sure to give them a FUNCTION_TYPE instead of a METHOD_TYPE, and we need to avoid using a BASELINK when looking them up. PR c++/79501 PR c++/100983 gcc/cp/ChangeLog: * decl.c (grokfndecl): Don't require that deduction guides are declared at namespace scope. Check that class-scope deduction guides have the same access as the member class template. (grokdeclarator): Pretend class-scope deduction guides are static. * search.c (lookup_member): Don't use a BASELINK for (class-scope) deduction guides. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/class-deduction92.C: New test. * g++.dg/cpp1z/class-deduction93.C: New test. * g++.dg/cpp1z/class-deduction94.C: New test. * g++.dg/cpp1z/class-deduction95.C: New test.
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 0df689b..01d64a1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10042,12 +10042,6 @@ grokfndecl (tree ctype,
if (deduction_guide_p (decl))
{
- if (!DECL_NAMESPACE_SCOPE_P (decl))
- {
- error_at (location, "deduction guide %qD must be declared at "
- "namespace scope", decl);
- return NULL_TREE;
- }
tree type = TREE_TYPE (DECL_NAME (decl));
if (in_namespace == NULL_TREE
&& CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
@@ -10057,6 +10051,13 @@ grokfndecl (tree ctype,
inform (location_of (type), " declared here");
return NULL_TREE;
}
+ if (DECL_CLASS_SCOPE_P (decl)
+ && current_access_specifier != declared_access (TYPE_NAME (type)))
+ {
+ error_at (location, "deduction guide %qD must have the same access "
+ "as %qT", decl, type);
+ inform (location_of (type), " declared here");
+ }
if (funcdef_flag)
error_at (location,
"deduction guide %qD must not have a function body", decl);
@@ -12037,6 +12038,10 @@ grokdeclarator (const cp_declarator *declarator,
storage_class = declspecs->storage_class;
if (storage_class == sc_static)
staticp = 1 + (decl_context == FIELD);
+ else if (decl_context == FIELD && sfk == sfk_deduction_guide)
+ /* Treat class-scope deduction guides as static member functions
+ so that they get a FUNCTION_TYPE instead of a METHOD_TYPE. */
+ staticp = 2;
if (virtualp)
{