public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: nick huang <nickhuang99@hotmail.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
Date: Fri, 24 Sep 2021 16:33:28 -0400	[thread overview]
Message-ID: <b8ba0c40-d078-b1e4-b4ad-d2cf62bd3d17@redhat.com> (raw)
In-Reply-To: <DM5PR0501MB37332890820CC359F119D4D7B5C89@DM5PR0501MB3733.namprd05.prod.outlook.com>

On 8/28/21 07:54, nick huang via Gcc-patches wrote:
> Reference with cv-qualifiers should be ignored instead of causing an error
> because standard accepts cv-qualified references introduced by typedef which
> is ignored.
> Therefore, the fix prevents GCC from reporting error by not setting variable
> "bad_quals" in case the reference is introduced by typedef. Still the
> cv-qualifier is silently ignored.
> Here I quote spec (https://timsong-cpp.github.io/cppwp/dcl.ref#1):
> "Cv-qualified references are ill-formed except when the cv-qualifiers
> are introduced through the use of a typedef-name ([dcl.typedef],
> [temp.param]) or decltype-specifier ([dcl.type.decltype]),
> in which case the cv-qualifiers are ignored."
> 
> PR c++/101783
> 
> gcc/cp/ChangeLog:
> 
> 2021-08-27  qingzhe huang  <nickhuang99@hotmail.com>
> 
> 	* tree.c (cp_build_qualified_type_real):

The git commit verifier rejects this commit message with

Checking 1fa0fbcdd15adf936ab4fae584f841beb35da1bb: FAILED ERR: missing 
description of a change:
"	* tree.c (cp_build_qualified_type_real):"

(your initial patch had a description here, you just need to copy it over)

ERR: PR 101783 in subject but not in changelog:
"c++: Suppress error when cv-qualified reference is introduced by 
typedef [PR101783]"

(the PR number needs to have a Tab before it)

In Jonathan's earlier reply he asked how you tested the patch; this 
message still doesn't say anything about that.

https://gcc.gnu.org/contribute.html#testing

What is the legal status of your contributions?

https://gcc.gnu.org/contribute.html#legal

Existing code tries to handle this with the tf_ignore_bad_quals, but the 
unnecessary use of typename gets past the code that tries to set the 
flag.  But your approach is nice and straightforward, so let's go ahead 
with it.

> gcc/testsuite/ChangeLog:
> 
> 2021-08-27  qingzhe huang  <nickhuang99@hotmail.com>
> 
> 	* g++.dg/parse/pr101783.C: New test.
> 
> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> index 8840932dba2..7aa4318a574 100644
> --- a/gcc/cp/tree.c
> +++ b/gcc/cp/tree.c
> @@ -1356,12 +1356,22 @@ cp_build_qualified_type_real (tree type,
>     /* A reference or method type shall not be cv-qualified.
>        [dcl.ref], [dcl.fct].  This used to be an error, but as of DR 295
>        (in CD1) we always ignore extra cv-quals on functions.  */
> +
> +  /* PR 101783

Let's cite where this comes from in the standard ([dcl.ref]/1), and not 
the PR number.

> +     Cv-qualified references are ill-formed except when the cv-qualifiers
> +     are introduced through the use of a typedef-name ([dcl.typedef],
> +     [temp.param]) or decltype-specifier ([dcl.type.decltype]),
> +     in which case the cv-qualifiers are ignored.
> +   */
>     if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
>         && (TYPE_REF_P (type)
>   	  || FUNC_OR_METHOD_TYPE_P (type)))
>       {
> -      if (TYPE_REF_P (type))
> +      // do NOT set bad_quals when non-method reference is introduced by typedef.
> +      if (TYPE_REF_P (type)
> +	  && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
>   	bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
> +      // non-method reference introduced by typedef is also dropped silently

These two // comments seem redundant with the quote from the standard 
above, let's drop them.

>         type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
>       }
>   
> diff --git a/gcc/testsuite/g++.dg/parse/pr101783.C b/gcc/testsuite/g++.dg/parse/pr101783.C
> new file mode 100644
> index 00000000000..4e0a435dd0b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/pr101783.C
> @@ -0,0 +1,5 @@
> +template<class T> struct A{
> +        typedef T& Type;
> +};
> +template<class T> void f(const typename A<T>::Type){}
> +template <> void f<int>(const typename A<int>::Type){}
> 
> 
> 


  parent reply	other threads:[~2021-09-24 20:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10  5:36 [PATCH] c++: Fix unnecessary error when top-level cv-qualifiers is dropped [PR101783] nick huang
2021-08-24 15:29 ` Jonathan Wakely
2021-08-28 11:54 ` [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783] nick huang
2021-09-24 11:15   ` *PING* " nick huang
2021-09-24 20:33   ` Jason Merrill [this message]
     [not found] <CAP6LXBsdU3xULuu8B3cEDGbcpHUXxF4roCC-zboWmtpGoPdVvw@mail.gmail.com>
2021-09-27  1:31 ` nick huang
2021-09-28 19:51   ` Jason Merrill
2021-09-30 18:24     ` nick huang
2021-10-01 13:29       ` Jason Merrill
2021-10-01 15:10         ` Nick Huang
2021-10-01 15:45           ` Jason Merrill
2021-10-01 19:52             ` Nick Huang
2021-10-05 19:40               ` 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=b8ba0c40-d078-b1e4-b4ad-d2cf62bd3d17@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nickhuang99@hotmail.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).