diff options
author | qingzhe huang <nickhuang99@hotmail.com> | 2021-10-01 10:46:35 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-10-01 11:44:47 -0400 |
commit | 7c99923f8c544ec07109e8333acb2c2388c38a1b (patch) | |
tree | 419bf8cdb8be6ccc0bcdca6911e692c2e23c0a7f | |
parent | 17374dab3eefd282977ad90743c9aff97f2e41ce (diff) | |
download | gcc-7c99923f8c544ec07109e8333acb2c2388c38a1b.zip gcc-7c99923f8c544ec07109e8333acb2c2388c38a1b.tar.gz gcc-7c99923f8c544ec07109e8333acb2c2388c38a1b.tar.bz2 |
c++: cv-qualified ref introduced by typedef [PR101783]
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.
-rw-r--r-- | gcc/cp/tree.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/pr101783.C | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3c62dd7..d67d785 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1403,11 +1403,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 0000000..4e0a435 --- /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){} |