public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1263] c++: access of dtor named by qualified template-id [PR100918]
@ 2021-06-07 16:06 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-06-07 16:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6cb35b606c39d5f21f3298c77bfbcaaef3fbc872

commit r12-1263-g6cb35b606c39d5f21f3298c77bfbcaaef3fbc872
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Jun 7 12:02:08 2021 -0400

    c++: access of dtor named by qualified template-id [PR100918]
    
    Here, when resolving the destructor named by Inner<int>::~Inner<int>
    (which is valid until C++20) we end up in cp_parser_lookup_name called
    indirectly from cp_parser_template_id to look up the name Inner from
    the scope Inner<int>.  The lookup naturally finds the injected-class-name,
    and because the flag is_template is true, we adjust this lookup result
    to the TEMPLATE_DECL Inner.  We then check access of this adjusted
    lookup result.  But this access check fails because the lookup scope is
    Inner<int> and the context_for_name_lookup for the TEMPLATE_DECL is
    Outer (whereas for the injected-class-name it's also Inner<int>).
    
    The simplest fix seems to be to check access of the original lookup
    result (the injected-class-name) instead of the adjusted result (the
    TEMPLATE_DECL).  So this patch moves the access check in
    cp_parser_lookup_name to before the injected-class-name adjustment.
    
            PR c++/100918
    
    gcc/cp/ChangeLog:
    
            * parser.c (cp_parser_lookup_name): Check access of the lookup
            result before we potentially adjust an injected-class-name to
            its TEMPLATE_DECL.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/access38.C: New test.

Diff:
---
 gcc/cp/parser.c                          | 24 +++++++++++++-----------
 gcc/testsuite/g++.dg/template/access38.C | 15 +++++++++++++++
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0649bf9a757..24f248af11c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -29505,6 +29505,19 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
   if (!decl || decl == error_mark_node)
     return error_mark_node;
 
+  /* If we have resolved the name of a member declaration, check to
+     see if the declaration is accessible.  When the name resolves to
+     set of overloaded functions, accessibility is checked when
+     overload resolution is done.  If we have a TREE_LIST, then the lookup
+     is either ambiguous or it found multiple injected-class-names, the
+     accessibility of which is trivially satisfied.
+
+     During an explicit instantiation, access is not checked at all,
+     as per [temp.explicit].  */
+  if (DECL_P (decl))
+    check_accessibility_of_qualified_id (decl, object_type, parser->scope,
+					 tf_warning_or_error);
+
   /* Pull out the template from an injected-class-name (or multiple).  */
   if (is_template)
     decl = maybe_get_template_decl_from_type_decl (decl);
@@ -29531,17 +29544,6 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
 	      || TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE
 	      || BASELINK_P (decl));
 
-  /* If we have resolved the name of a member declaration, check to
-     see if the declaration is accessible.  When the name resolves to
-     set of overloaded functions, accessibility is checked when
-     overload resolution is done.
-
-     During an explicit instantiation, access is not checked at all,
-     as per [temp.explicit].  */
-  if (DECL_P (decl))
-    check_accessibility_of_qualified_id (decl, object_type, parser->scope,
-					 tf_warning_or_error);
-
   maybe_record_typedef_use (decl);
 
   return cp_expr (decl, name_location);
diff --git a/gcc/testsuite/g++.dg/template/access38.C b/gcc/testsuite/g++.dg/template/access38.C
new file mode 100644
index 00000000000..488f8650c97
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/access38.C
@@ -0,0 +1,15 @@
+// PR c++/100918
+
+struct Outer {
+  template<class T>
+  struct Inner { ~Inner(); };
+};
+
+template<>
+Outer::Inner<int>::~Inner<int>() { } // { dg-error "template-id" "" { target c++20 } }
+
+template<class T>
+Outer::Inner<T>::~Inner<T>() { } // { dg-error "template-id" "" { target c++20 } }
+
+Outer::Inner<int> x;
+Outer::Inner<char> y;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-07 16:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-07 16:06 [gcc r12-1263] c++: access of dtor named by qualified template-id [PR100918] Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).