]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: top-level cv-quals on type of NTTP [PR100893]
authorPatrick Palka <ppalka@redhat.com>
Fri, 4 Jun 2021 18:08:26 +0000 (14:08 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 4 Jun 2021 18:08:26 +0000 (14:08 -0400)
commit6f8c9691495ad5a307db98dc19c3296ee4e6de64
tree9f4269a63672a71d2c308b6d8e8d85334a36e1fa
parent5357ab75dedef403b0eebf9277d61d1cbeb5898f
c++: top-level cv-quals on type of NTTP [PR100893]

Here, we're rejecting the specialization of g<T,F> with T=A, F=&f in
param4.C below due to a spurious constness mismatch between the type of
the template argument &f and the substituted type of the parm F (the
latter has a top-level const).  Note that this mismatch doesn't occur
with object pointers because in that case a call to
perform_qualification_conversions from convert_nontype_argument
implicitly adds a top-level const to the argument (via a cast) to match.

This however seems to be a manifestation of a more general conformance
issue: we're not dropping top-level cv-quals on the substituted
type of an NTTP as per [temp.param]/6 (we only do so at parse time in
process_template_parm).  So this patch makes convert_template_argument
drop top-level cv-quals accordingly.

PR c++/100893

gcc/cp/ChangeLog:

* pt.c (convert_template_argument): Strip top-level cv-quals
on the substituted type of a non-type template parameter.

gcc/testsuite/ChangeLog:

* g++.dg/template/param4.C: New test.
* g++.dg/template/param5.C: New test.
* g++.dg/cpp1z/nontype-auto19.C: New test.
* g++.dg/cpp2a/concepts-decltype.C: Don't expect that the
deduced type of a decltype(auto) NTTP has top-level cv-quals.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/nontype-auto19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-decltype.C
gcc/testsuite/g++.dg/template/param4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/param5.C [new file with mode: 0644]