public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: cv-qualified dependent name of alias tmpl [PR100592]
Date: Wed, 2 Jun 2021 15:55:33 -0400	[thread overview]
Message-ID: <0e38e572-6392-a172-8873-7985eacac30c@redhat.com> (raw)
In-Reply-To: <20210602183934.958366-1-ppalka@redhat.com>

On 6/2/21 2:39 PM, Patrick Palka wrote:
> 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.

Hmm, the patch looks fine, but why does the TYPE_DECL test fail for the 
alias?

> We already have the tf_ignore_bad_quals flag for this situation, but
> the TYPENAME_TYPE branch of tsubst for some reason doesn't always use
> this flag.  This patch just makes tsubst unconditionally use this flag
> when substituting a TYPENAME_TYPE.
> 
> This change also causes us to drop bogus __restrict__ qualifiers more
> consistently during substitution, as in qualttp20.C below where we no
> longer diagnose the __restrict__ qualifier on B1<AS>::r.  Note that if
> we artificially introduced a typedef as in B1<AS>::s we silently dropped
> __restrict__ even before this patch, so this seems like an improvement.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
> 
> 	PR c++/100592
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.c (tsubst) <case TYPENAME_TYPE>: Always pass
> 	tf_ignore_bad_quals to cp_build_qualified_type.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp0x/alias-decl-71.C: New test.
> 	* g++.dg/template/qualttp20.C: Remove dg-error and augment.
> ---
>   gcc/cp/pt.c                                | 10 ++++------
>   gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C | 13 +++++++++++++
>   gcc/testsuite/g++.dg/template/qualttp20.C  |  6 ++++--
>   3 files changed, 21 insertions(+), 8 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-71.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 86259e900e9..2da5407a2a7 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -16066,10 +16066,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>   	if (f == error_mark_node)
>   	  return f;
>   	if (TREE_CODE (f) == TYPE_DECL)
> -	  {
> -	    complain |= tf_ignore_bad_quals;
> -	    f = TREE_TYPE (f);
> -	  }
> +	  f = TREE_TYPE (f);
>   
>   	if (TREE_CODE (f) != TYPENAME_TYPE)
>   	  {
> @@ -16091,8 +16088,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>   	      }
>   	  }
>   
> -	return cp_build_qualified_type_real
> -	  (f, cp_type_quals (f) | cp_type_quals (t), complain);
> +	int quals = cp_type_quals (f) | cp_type_quals (t);
> +	complain |= tf_ignore_bad_quals;
> +	return cp_build_qualified_type_real (f, quals, complain);
>         }
>   
>       case UNBOUND_CLASS_TEMPLATE:
> 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&;
> diff --git a/gcc/testsuite/g++.dg/template/qualttp20.C b/gcc/testsuite/g++.dg/template/qualttp20.C
> index 52989bae538..3281f5d9eab 100644
> --- a/gcc/testsuite/g++.dg/template/qualttp20.C
> +++ b/gcc/testsuite/g++.dg/template/qualttp20.C
> @@ -10,13 +10,15 @@ struct AS
>   {
>     typedef void (myT) ();
>     struct L {};
> +  typedef struct {} M;
>     
>   };
>   
>   
>   template <typename T> struct B1 : T
>   {
> -  typedef typename T::L __restrict__ r;// { dg-error "'__restrict__' qualifiers cannot" }
> +  typedef typename T::L __restrict__ r;
> +  typedef typename T::M __restrict__ s;
>     typedef typename T::myT __restrict__ p;
>   
>     // The following are DR 295 dependent
> @@ -32,5 +34,5 @@ template <typename T> struct B2 : T
>     myconst b;
>   };
>   
> -B1<AS> b1;	// { dg-message "required" }
> +B1<AS> b1;
>   B2<AS> b2;
> 


  reply	other threads:[~2021-06-02 19:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02 18:39 Patrick Palka
2021-06-02 19:55 ` Jason Merrill [this message]
2021-06-02 20:50   ` Patrick Palka
2021-06-02 20:56     ` Patrick Palka
2021-06-02 21:37       ` Jason Merrill
2021-06-02 23:05         ` Patrick Palka
2021-06-03  3:55           ` Jason Merrill

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=0e38e572-6392-a172-8873-7985eacac30c@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /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).