public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1183] c++: cv-qualified dependent name of alias tmpl [PR100592]
Date: Thu,  3 Jun 2021 13:39:50 +0000 (GMT)	[thread overview]
Message-ID: <20210603133950.15CAD3835833@sourceware.org> (raw)

https://gcc.gnu.org/g:d999d9b7e53b9a9cd2004a19e84c637e5e5013f5

commit r12-1183-gd999d9b7e53b9a9cd2004a19e84c637e5e5013f5
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Jun 3 09:39:13 2021 -0400

    c++: cv-qualified dependent name of alias tmpl [PR100592]
    
    Here, the dependent template name in the return type of f() resolves to
    an alias of int& after substitution, and we end up complaining about
    qualifying this reference type with 'const' from cp_build_qualified_type
    rather than just silently dropping the qualification as per [dcl.ref]/1.
    
    The problem is ultimately that make_typename_type ignores the
    tf_keep_type_decl flag when the dependent name is a template-id.  This
    in turn causes the TYPE_DECL check within tsubst <case TYPENAME_TYPE>
    to fail, and so we end up not passing tf_ignore_bad_quals to
    cp_build_qualified_type.  This patch fixes this by making
    make_typename_type respect the tf_keep_type_decl flag in this situation.
    
            PR c++/100592
    
    gcc/cp/ChangeLog:
    
            * decl.c (make_typename_type): After calling
            lookup_template_class, adjust the result to its TYPE_NAME and
            then consider the tf_keep_type_decl flag.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/alias-decl-71.C: New test.

Diff:
---
 gcc/cp/decl.c                              | 13 +++++++++----
 gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C | 13 +++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index fb21a3a1ae8..a3687dbb0dd 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -4136,10 +4136,15 @@ make_typename_type (tree context, tree name, enum tag_types tag_type,
     return error_mark_node;
 
   if (want_template)
-    return lookup_template_class (t, TREE_OPERAND (fullname, 1),
-				  NULL_TREE, context,
-				  /*entering_scope=*/0,
-				  complain | tf_user);
+    {
+      t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
+				 NULL_TREE, context,
+				 /*entering_scope=*/0,
+				 complain | tf_user);
+      if (t == error_mark_node)
+	return error_mark_node;
+      t = TYPE_NAME (t);
+    }
   
   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
     t = TREE_TYPE (t);
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C
new file mode 100644
index 00000000000..6a61f93a0b0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C
@@ -0,0 +1,13 @@
+// PR c++/100592
+// { dg-do compile { target c++11 } }
+
+template<bool>
+struct meta {
+  template<class> using if_c = int&;
+};
+
+template<bool B>
+typename meta<B>::template if_c<void> const f();
+
+using type = decltype(f<true>());
+using type = int&;


                 reply	other threads:[~2021-06-03 13:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210603133950.15CAD3835833@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).