* [PATCH] c++: Fix unnecessary error when top-level cv-qualifiers is dropped [PR101783]
@ 2021-08-10 5:36 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
0 siblings, 2 replies; 13+ messages in thread
From: nick huang @ 2021-08-10 5:36 UTC (permalink / raw)
To: gcc-patches
The root cause of this bug is that it considers reference with cv-qualifiers
as an error by generating value for variable "bad_quals". However, this is
not correct for case of typedef. Here I quote spec:
"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."
2021-08-09 Qingzhe Huang <nickhuang99@hotmail.com>
PR c++/101387
gcc/cp/ChangeLog:
PR c++/101387
* tree.c (cp_build_qualified_type_real): Excluding typedef from error
gcc/testsuite/ChangeLog:
PR c++/101387
* g++.dg/parse/pr101783.C: New test.
diff --git gcc/cp/tree.c gcc/cp/tree.c
index 10b818d1370..a4ae3eee6d0 100644
--- gcc/cp/tree.c
+++ gcc/cp/tree.c
@@ -1361,11 +1361,18 @@ 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. */
+ /* 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))
+ if (TYPE_REF_P (type)
+ //A reference from typedef is not an error, but ignored.
+ && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
}
diff --git gcc/testsuite/g++.dg/parse/pr101783.C gcc/testsuite/g++.dg/parse/pr101783.C
new file mode 100644
index 00000000000..8f8f8b1faeb
--- /dev/null
+++ gcc/testsuite/g++.dg/parse/pr101783.C
@@ -0,0 +1,10 @@
+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){}
+struct B{};
+template<>
+void f<B>(const A<B>::Type){}
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Fix unnecessary error when top-level cv-qualifiers is dropped [PR101783]
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
1 sibling, 0 replies; 13+ messages in thread
From: Jonathan Wakely @ 2021-08-24 15:29 UTC (permalink / raw)
To: nickhuang99; +Cc: gcc-patches
>PR c++/101387
>
>gcc/cp/ChangeLog:
> PR c++/101387
> * tree.c (cp_build_qualified_type_real): Excluding typedef from error
>
>gcc/testsuite/ChangeLog:
> PR c++/101387
> * g++.dg/parse/pr101783.C: New test.
This is the wrong PR number.
How has this ptch been tested? Have you bootstrapped the compiler and
run the full testsuite?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
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 ` nick huang
2021-09-24 11:15 ` *PING* " nick huang
2021-09-24 20:33 ` Jason Merrill
1 sibling, 2 replies; 13+ messages in thread
From: nick huang @ 2021-08-28 11:54 UTC (permalink / raw)
To: gcc-patches
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):
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
+ 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
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){}
^ permalink raw reply [flat|nested] 13+ messages in thread
* *PING* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
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 ` nick huang
2021-09-24 20:33 ` Jason Merrill
1 sibling, 0 replies; 13+ messages in thread
From: nick huang @ 2021-09-24 11:15 UTC (permalink / raw)
To: gcc-patches
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):
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
+ 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
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){}
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
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
1 sibling, 0 replies; 13+ messages in thread
From: Jason Merrill @ 2021-09-24 20:33 UTC (permalink / raw)
To: nick huang, gcc-patches
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){}
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-10-01 19:52 ` Nick Huang
@ 2021-10-05 19:40 ` Jason Merrill
0 siblings, 0 replies; 13+ messages in thread
From: Jason Merrill @ 2021-10-05 19:40 UTC (permalink / raw)
To: Nick Huang; +Cc: Gcc-patches
On 10/1/21 15:52, Nick Huang wrote:
>> ...the subject line for the commit should be the first line of the
>> commit message, followed by a blank line, followed by the description of
>> the patch; without the subject line, git format-patch thought your whole
>> description was the subject of the patch.
>
> oh, I didn't realize this without your mentioning it. I read this guide
> (https://gcc.gnu.org/codingconventions.html#ChangeLogs) many times
> and still don't get this. I guess it was written long long ago.
FYI that's a git thing, not a ChangeLog thing. From the git
format-patch manual:
> By default, the subject of a single patch is "[PATCH] " followed by the
> concatenation of lines from the commit message up to the first blank
> line (see the DISCUSSION section of git-commit(1)).
And from git-commit(1):
> Though not required, it’s a good idea to begin the commit message with
> a single short (less than 50 character) line summarizing the change,
> followed by a blank line and then a more thorough description. The text
> up to the first blank line in a commit message is treated as the commit
> title, and that title is used throughout Git. For example, git-format-
> patch(1) turns a commit into email, and it uses the title on the
> Subject line and the rest of the commit in the body.
But yes, it would be good to give more of this instruction in the gcc
contribute.html.
Jason
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-10-01 15:45 ` Jason Merrill
@ 2021-10-01 19:52 ` Nick Huang
2021-10-05 19:40 ` Jason Merrill
0 siblings, 1 reply; 13+ messages in thread
From: Nick Huang @ 2021-10-01 19:52 UTC (permalink / raw)
To: Jason Merrill; +Cc: Gcc-patches
> ...the subject line for the commit should be the first line of the
> commit message, followed by a blank line, followed by the description of
> the patch; without the subject line, git format-patch thought your whole
> description was the subject of the patch.
oh, I didn't realize this without your mentioning it. I read this guide
(https://gcc.gnu.org/codingconventions.html#ChangeLogs) many times
and still don't get this. I guess it was written long long ago.
> I've corrected this and pushed the patch, thanks!
I do thank you and without your help I might never accomplish this task.
Once again appreciate your patient help!
On Fri, Oct 1, 2021 at 11:46 AM Jason Merrill <jason@redhat.com> wrote:
>
> On 10/1/21 11:10, Nick Huang wrote:
> >> gcc-verify still fails with this version:
> >>
> >>> ERR: line should start with a tab: " PR c++/101783"
> >>> ERR: line should start with a tab: " * tree.c (cp_build_qualified_type_real): Excluding typedef from error"
> >>> ERR: line should start with a tab: " PR c++/101783"
> >>> ERR: line should start with a tab: " * g++.dg/parse/pr101783.C: New test."
> >
> >> It might work better to attach the output of git format-patch.
> > Sorry for my clumsy copy/paste from git commit message. I now attach
> > git format-patch output
> > file as attachment. Also maybe for a little convenience of your work,
> > I also attach the original
> > commit message file when I do git commit -F.
>
> Thanks, but that isn't necessary; it should be the same in the
> format-patch output, except...
>
> > From e592a475030d99647de736d294cb3c6a7588af49 Mon Sep 17 00:00:00 2001
> > From: qingzhe huang <nickhuang99@hotmail.com>
> > Date: Fri, 1 Oct 2021 10:46:35 -0400
> > Subject: [PATCH] The root cause of this bug is that it considers reference
> > with cv-qualifiers as an error by generating value for variable "bad_quals".
> > However, this is not correct for case of typedef. Here I quote spec
> > [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."
>
> ...the subject line for the commit should be the first line of the
> commit message, followed by a blank line, followed by the description of
> the patch; without the subject line, git format-patch thought your whole
> description was the subject of the patch.
>
> I've corrected this and pushed the patch, thanks!
>
> Jason
>
--
nick huang/qingzhe huang
http://www.staroceans.com
http://www.staroceans.com/english.htm
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-10-01 15:10 ` Nick Huang
@ 2021-10-01 15:45 ` Jason Merrill
2021-10-01 19:52 ` Nick Huang
0 siblings, 1 reply; 13+ messages in thread
From: Jason Merrill @ 2021-10-01 15:45 UTC (permalink / raw)
To: Nick Huang; +Cc: nick huang, Gcc-patches
On 10/1/21 11:10, Nick Huang wrote:
>> gcc-verify still fails with this version:
>>
>>> ERR: line should start with a tab: " PR c++/101783"
>>> ERR: line should start with a tab: " * tree.c (cp_build_qualified_type_real): Excluding typedef from error"
>>> ERR: line should start with a tab: " PR c++/101783"
>>> ERR: line should start with a tab: " * g++.dg/parse/pr101783.C: New test."
>
>> It might work better to attach the output of git format-patch.
> Sorry for my clumsy copy/paste from git commit message. I now attach
> git format-patch output
> file as attachment. Also maybe for a little convenience of your work,
> I also attach the original
> commit message file when I do git commit -F.
Thanks, but that isn't necessary; it should be the same in the
format-patch output, except...
> From e592a475030d99647de736d294cb3c6a7588af49 Mon Sep 17 00:00:00 2001
> From: qingzhe huang <nickhuang99@hotmail.com>
> Date: Fri, 1 Oct 2021 10:46:35 -0400
> Subject: [PATCH] The root cause of this bug is that it considers reference
> with cv-qualifiers as an error by generating value for variable "bad_quals".
> However, this is not correct for case of typedef. Here I quote spec
> [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."
...the subject line for the commit should be the first line of the
commit message, followed by a blank line, followed by the description of
the patch; without the subject line, git format-patch thought your whole
description was the subject of the patch.
I've corrected this and pushed the patch, thanks!
Jason
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-10-01 13:29 ` Jason Merrill
@ 2021-10-01 15:10 ` Nick Huang
2021-10-01 15:45 ` Jason Merrill
0 siblings, 1 reply; 13+ messages in thread
From: Nick Huang @ 2021-10-01 15:10 UTC (permalink / raw)
To: Jason Merrill; +Cc: nick huang, Gcc-patches
[-- Attachment #1: Type: text/plain, Size: 3203 bytes --]
> gcc-verify still fails with this version:
>
> > ERR: line should start with a tab: " PR c++/101783"
> > ERR: line should start with a tab: " * tree.c (cp_build_qualified_type_real): Excluding typedef from error"
> > ERR: line should start with a tab: " PR c++/101783"
> > ERR: line should start with a tab: " * g++.dg/parse/pr101783.C: New test."
> It might work better to attach the output of git format-patch.
Sorry for my clumsy copy/paste from git commit message. I now attach
git format-patch output
file as attachment. Also maybe for a little convenience of your work,
I also attach the original
commit message file when I do git commit -F.
> Also, your commit subject line is too long, at 83 characters: It must be
> under 75 characters, and preferably closer to 50. I might shorten it to
Please go ahead. I will pay attention to this next time. Thank you!
> A change description in the ChangeLog should use present tense
> ("Exclude"), have a period at the end, and line wrap at 75 characters
> like the rest of the commit message. So,
>
> * tree.c (cp_build_qualified_type_real): Exclude typedef from
> error.
>
Modified as suggested.
> > + ([dcl.type.decltype]),in which case the cv-qualifiers are ignored.
> > + */
>
> We usually don't put */ on its own line.
Adjusted.
Once again I thank you for your patience and really appreciate it.
On Fri, Oct 1, 2021 at 9:29 AM Jason Merrill via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On 9/30/21 14:24, nick huang wrote:
> >>> You may need to run contrib/gcc-git-customization.sh to get the git
> >>> gcc-verify command.
> > I re-setup and can use git gcc-verify. Now I can see it rejects because I forgot to add a
> > description of modified file. Now that it passes gcc-verify and I attach the changelog
> > as attachment.
> >
> > Thank you again for your patient explanation and help!
>
> You're welcome, thanks for your patience as well! Unfortunately, git
> gcc-verify still fails with this version:
>
> > ERR: line should start with a tab: " PR c++/101783"
> > ERR: line should start with a tab: " * tree.c (cp_build_qualified_type_real): Excluding typedef from error"
> > ERR: line should start with a tab: " PR c++/101783"
> > ERR: line should start with a tab: " * g++.dg/parse/pr101783.C: New test."
>
> It might work better to attach the output of git format-patch.
>
> Also, your commit subject line is too long, at 83 characters: It must be
> under 75 characters, and preferably closer to 50. I might shorten it to
>
> c++: cv-qualified ref introduced by typedef [PR101783]
>
> > * tree.c (cp_build_qualified_type_real): Excluding typedef from error
>
> A change description in the ChangeLog should use present tense
> ("Exclude"), have a period at the end, and line wrap at 75 characters
> like the rest of the commit message. So,
>
> * tree.c (cp_build_qualified_type_real): Exclude typedef from
> error.
>
> > + ([dcl.type.decltype]),in which case the cv-qualifiers are ignored.
> > + */
>
> We usually don't put */ on its own line.
>
> Jason
>
--
nick huang/qingzhe huang
http://www.staroceans.com
http://www.staroceans.com/english.htm
[-- Attachment #2: commit-comment-10-01.txt --]
[-- Type: text/plain, Size: 697 bytes --]
The root cause of this bug is that it considers reference with
cv-qualifiers as an error by generating value for variable "bad_quals".
However, this is not correct for case of typedef. Here I quote spec
[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."
2021-09-30 qingzhe huang <nickhuang99@hotmail.com>
gcc/cp/ChangeLog:
PR c++/101783
* tree.c (cp_build_qualified_type_real): Exclude typedef from
error.
gcc/testsuite/ChangeLog:
PR c++/101783
* g++.dg/parse/pr101783.C: New test.
[-- Attachment #3: 0001-The-root-cause-of-this-bug-is-that-it-considers-refe.patch --]
[-- Type: text/x-patch, Size: 2551 bytes --]
From e592a475030d99647de736d294cb3c6a7588af49 Mon Sep 17 00:00:00 2001
From: qingzhe huang <nickhuang99@hotmail.com>
Date: Fri, 1 Oct 2021 10:46:35 -0400
Subject: [PATCH] The root cause of this bug is that it considers reference
with cv-qualifiers as an error by generating value for variable "bad_quals".
However, this is not correct for case of typedef. Here I quote spec
[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."
2021-09-30 qingzhe huang <nickhuang99@hotmail.com>
gcc/cp/ChangeLog:
PR c++/101783
* tree.c (cp_build_qualified_type_real): Exclude typedef from
error.
gcc/testsuite/ChangeLog:
PR c++/101783
* g++.dg/parse/pr101783.C: New test.
---
gcc/cp/tree.c | 9 ++++++++-
gcc/testsuite/g++.dg/parse/pr101783.C | 5 +++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/parse/pr101783.C
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 8840932dba2..6a6f8a642cb 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1356,11 +1356,18 @@ 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. */
+
+ /* [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. */
if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
&& (TYPE_REF_P (type)
|| FUNC_OR_METHOD_TYPE_P (type)))
{
- if (TYPE_REF_P (type))
+ 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);
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){}
--
2.17.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-09-30 18:24 ` nick huang
@ 2021-10-01 13:29 ` Jason Merrill
2021-10-01 15:10 ` Nick Huang
0 siblings, 1 reply; 13+ messages in thread
From: Jason Merrill @ 2021-10-01 13:29 UTC (permalink / raw)
To: nick huang, Gcc-patches
On 9/30/21 14:24, nick huang wrote:
>>> You may need to run contrib/gcc-git-customization.sh to get the git
>>> gcc-verify command.
> I re-setup and can use git gcc-verify. Now I can see it rejects because I forgot to add a
> description of modified file. Now that it passes gcc-verify and I attach the changelog
> as attachment.
>
> Thank you again for your patient explanation and help!
You're welcome, thanks for your patience as well! Unfortunately, git
gcc-verify still fails with this version:
> ERR: line should start with a tab: " PR c++/101783"
> ERR: line should start with a tab: " * tree.c (cp_build_qualified_type_real): Excluding typedef from error"
> ERR: line should start with a tab: " PR c++/101783"
> ERR: line should start with a tab: " * g++.dg/parse/pr101783.C: New test."
It might work better to attach the output of git format-patch.
Also, your commit subject line is too long, at 83 characters: It must be
under 75 characters, and preferably closer to 50. I might shorten it to
c++: cv-qualified ref introduced by typedef [PR101783]
> * tree.c (cp_build_qualified_type_real): Excluding typedef from error
A change description in the ChangeLog should use present tense
("Exclude"), have a period at the end, and line wrap at 75 characters
like the rest of the commit message. So,
* tree.c (cp_build_qualified_type_real): Exclude typedef from
error.
> + ([dcl.type.decltype]),in which case the cv-qualifiers are ignored.
> + */
We usually don't put */ on its own line.
Jason
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-09-28 19:51 ` Jason Merrill
@ 2021-09-30 18:24 ` nick huang
2021-10-01 13:29 ` Jason Merrill
0 siblings, 1 reply; 13+ messages in thread
From: nick huang @ 2021-09-30 18:24 UTC (permalink / raw)
To: Jason Merrill, Gcc-patches
[-- Attachment #1: Type: text/plain, Size: 8739 bytes --]
>>You may need to run contrib/gcc-git-customization.sh to get the git
>>gcc-verify command.
I re-setup and can use git gcc-verify. Now I can see it rejects because I forgot to add a
description of modified file. Now that it passes gcc-verify and I attach the changelog
as attachment.
Thank you again for your patient explanation and help!
On 9/26/21 21:31, nick huang via Gcc-patches wrote:
> Hi Jason,
>
> 1. Thank you very much for your detailed comments for my patch and I really appreciate it! Here is my revised patch:
>
> The root cause of this bug is that it considers reference with
> cv-qualifiers as an error by generating value for variable "bad_quals".
> However, this is not correct for case of typedef. Here I quote spec:
> "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."
>
> 2021-09-25 qingzhe huang <nickhuang99@hotmail.com>
>
> gcc/cp/
> PR c++/101783
> * tree.c (cp_build_qualified_type_real):
git gcc-verify still rejects this line with
ERR: missing description of a change: " * tree.c
(cp_build_qualified_type_real):"
You may need to run contrib/gcc-git-customization.sh to get the git
gcc-verify command.
> gcc/testsuite/
> PR c++/101783
> * g++.dg/parse/pr101783.C: New test.
> -------------- next part --------------
Please drop this line, it breaks git gcc-verify when I apply the patch
with git am. The patch should start immediately after the ChangeLog
entries.
> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> index 8840932dba2..d5c8daeb340 100644
> --- a/gcc/cp/tree.c
> +++ b/gcc/cp/tree.c
> @@ -1356,11 +1356,18 @@ 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. */
> +
> + /* Cv-qualified references are ill-formed except when the cv-qualifiers
In my previous reply I meant please add "[dcl.ref]/1" at the beginning
of this comment.
> + 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))
> + 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);
> 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){}
>
>
>
> 2.
>> In Jonathan's earlier reply he asked how you tested the patch; this
>> message still doesn't say anything about that.
> I communicated with Mr. Jonathan in private email, worrying my naive question might pollute the public maillist. The following is major part of this communication and I attached original part in attachment.
>
>>>> How has this patch been tested? Have you bootstrapped the compiler and
>>>> run the full testsuite?
> Here is how I am doing:
> a) build original 10.2.0 from scratch and make check to get both "testsuite/gcc/gcc.sum"
> and "testsuite/g++/g++.sum".
> b) apply my patch and build from scratch and make check to get both two files above.
> c) compare two run's *.sum files to see if there is any difference.
>
> (Later I realized there is tool "contrib/compare_tests" is a good help of doing so.)
>
> 3.
>> What is the legal status of your contributions?
> I thought small patch didn't require assignment. However, I just sent email to assign@gnu.org to request assignment.
> Alternatively, I am not sure if adding this "signoff" tag in submission will help?
> Signed-off-by: qingzhe huang <nickhuang99@hotmail.com>
>
>
> Thank you again!
>
>
>> 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){}
>>>
>>>
[-- Attachment #2: pr101783.txt --]
[-- Type: text/plain, Size: 2158 bytes --]
The root cause of this bug is that it considers reference with
cv-qualifiers as an error by generating value for variable "bad_quals".
However, this is not correct for case of typedef. Here I quote spec
[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."
2021-09-30 qingzhe huang <nickhuang99@hotmail.com>
gcc/cp/ChangeLog:
PR c++/101783
* tree.c (cp_build_qualified_type_real): Excluding typedef from error
gcc/testsuite/ChangeLog:
PR c++/101783
* g++.dg/parse/pr101783.C: New test.
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 8840932dba2..cdc27facf02 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1356,11 +1356,18 @@ 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. */
+
+ /* [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.
+ */
if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
&& (TYPE_REF_P (type)
|| FUNC_OR_METHOD_TYPE_P (type)))
{
- if (TYPE_REF_P (type))
+ 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);
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){}
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
2021-09-27 1:31 ` nick huang
@ 2021-09-28 19:51 ` Jason Merrill
2021-09-30 18:24 ` nick huang
0 siblings, 1 reply; 13+ messages in thread
From: Jason Merrill @ 2021-09-28 19:51 UTC (permalink / raw)
To: nick huang, Gcc-patches
On 9/26/21 21:31, nick huang via Gcc-patches wrote:
> Hi Jason,
>
> 1. Thank you very much for your detailed comments for my patch and I really appreciate it! Here is my revised patch:
>
> The root cause of this bug is that it considers reference with
> cv-qualifiers as an error by generating value for variable "bad_quals".
> However, this is not correct for case of typedef. Here I quote spec:
> "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."
>
> 2021-09-25 qingzhe huang <nickhuang99@hotmail.com>
>
> gcc/cp/
> PR c++/101783
> * tree.c (cp_build_qualified_type_real):
git gcc-verify still rejects this line with
ERR: missing description of a change: " * tree.c
(cp_build_qualified_type_real):"
You may need to run contrib/gcc-git-customization.sh to get the git
gcc-verify command.
> gcc/testsuite/
> PR c++/101783
> * g++.dg/parse/pr101783.C: New test.
> -------------- next part --------------
Please drop this line, it breaks git gcc-verify when I apply the patch
with git am. The patch should start immediately after the ChangeLog
entries.
> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> index 8840932dba2..d5c8daeb340 100644
> --- a/gcc/cp/tree.c
> +++ b/gcc/cp/tree.c
> @@ -1356,11 +1356,18 @@ 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. */
> +
> + /* Cv-qualified references are ill-formed except when the cv-qualifiers
In my previous reply I meant please add "[dcl.ref]/1" at the beginning
of this comment.
> + 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))
> + 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);
> 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){}
>
>
>
> 2.
>> In Jonathan's earlier reply he asked how you tested the patch; this
>> message still doesn't say anything about that.
> I communicated with Mr. Jonathan in private email, worrying my naive question might pollute the public maillist. The following is major part of this communication and I attached original part in attachment.
>
>>>> How has this patch been tested? Have you bootstrapped the compiler and
>>>> run the full testsuite?
> Here is how I am doing:
> a) build original 10.2.0 from scratch and make check to get both "testsuite/gcc/gcc.sum"
> and "testsuite/g++/g++.sum".
> b) apply my patch and build from scratch and make check to get both two files above.
> c) compare two run's *.sum files to see if there is any difference.
>
> (Later I realized there is tool "contrib/compare_tests" is a good help of doing so.)
>
> 3.
>> What is the legal status of your contributions?
> I thought small patch didn't require assignment. However, I just sent email to assign@gnu.org to request assignment.
> Alternatively, I am not sure if adding this "signoff" tag in submission will help?
> Signed-off-by: qingzhe huang <nickhuang99@hotmail.com>
>
>
> Thank you again!
>
>
>> 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){}
>>>
>>>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783]
[not found] <CAP6LXBsdU3xULuu8B3cEDGbcpHUXxF4roCC-zboWmtpGoPdVvw@mail.gmail.com>
@ 2021-09-27 1:31 ` nick huang
2021-09-28 19:51 ` Jason Merrill
0 siblings, 1 reply; 13+ messages in thread
From: nick huang @ 2021-09-27 1:31 UTC (permalink / raw)
To: David Edelsohn via Gcc-patches
[-- Attachment #1: Type: text/plain, Size: 7597 bytes --]
Hi Jason,
1. Thank you very much for your detailed comments for my patch and I really appreciate it! Here is my revised patch:
The root cause of this bug is that it considers reference with
cv-qualifiers as an error by generating value for variable "bad_quals".
However, this is not correct for case of typedef. Here I quote spec:
"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."
2021-09-25 qingzhe huang <nickhuang99@hotmail.com>
gcc/cp/
PR c++/101783
* tree.c (cp_build_qualified_type_real):
gcc/testsuite/
PR c++/101783
* g++.dg/parse/pr101783.C: New test.
-------------- next part --------------
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 8840932dba2..d5c8daeb340 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1356,11 +1356,18 @@ 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. */
+
+ /* 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))
+ 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);
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){}
2.
> In Jonathan's earlier reply he asked how you tested the patch; this
> message still doesn't say anything about that.
I communicated with Mr. Jonathan in private email, worrying my naive question might pollute the public maillist. The following is major part of this communication and I attached original part in attachment.
>>>How has this patch been tested? Have you bootstrapped the compiler and
>>>run the full testsuite?
Here is how I am doing:
a) build original 10.2.0 from scratch and make check to get both "testsuite/gcc/gcc.sum"
and "testsuite/g++/g++.sum".
b) apply my patch and build from scratch and make check to get both two files above.
c) compare two run's *.sum files to see if there is any difference.
(Later I realized there is tool "contrib/compare_tests" is a good help of doing so.)
3.
> What is the legal status of your contributions?
I thought small patch didn't require assignment. However, I just sent email to assign@gnu.org to request assignment.
Alternatively, I am not sure if adding this "signoff" tag in submission will help?
Signed-off-by: qingzhe huang <nickhuang99@hotmail.com>
Thank you again!
> 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){}
> >
> >
> >
[-- Attachment #2: how-to-test.txt --]
[-- Type: text/plain, Size: 1463 bytes --]
> >>>How has this ptch been tested? Have you bootstrapped the compiler and
> >>>run the full testsuite?
> Here is how I am doing:
> a) build original 10.2.0 from scratch and make check to get both "testsuite/gcc/gcc.sum"
> and "testsuite/g++/g++.sum".
> This is my configure params:
>
> configure --prefix=/home/nick/Downloads/gcc-10.2.0-test/gcc_install/gcc-10.2.0_install
> --enable-bootstrap --enable-shared --enable-threads=posix
These are enabled by default.
> --enable-checking=release
You don't want this when testing changes on trunk, it disables important checks.
> --enable-__cxa_atexit --disable-libunwind-exceptions --enable-linker-build-id
All enabled by default.
>--enable-languages=c,c++,lto --disable-vtable-verify --with-default-libstdcxx-abi=new --enable-libstdcxx-debug --without-included-gettext --enable-plugin --disable-initfini-array --disable-libgcj --enable-plugin --disable-multilib --with-tune=generic --build=x86_64-unknown-linux-gnu --target=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --with-pkgversion=nick-nick-HP-Laptop
>
> b) apply my patch and build from scratch and make check to get both two files above.
> c) compare two run's *.sum files to see if there is any difference.
>
> If above procedure is correct,
Your configure command is overcomplicated, but apart from the
--enable-checking option it is harmless.
>I will re-do and re-submit the patch email with corrected PR number.
Yes, please do.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2021-10-05 19:40 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
[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
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).