]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix common_iterator::operator-> [PR95322]
authorPatrick Palka <ppalka@redhat.com>
Tue, 26 May 2020 20:17:34 +0000 (16:17 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 28 May 2020 01:37:16 +0000 (21:37 -0400)
commitfc78e991c35a5ee14efafb4e5566a9570fa31dd4
treef5d344013baefda8065615c0aef8a7b7389ab820
parent50cd4503e59f29e379d0515c48e67d0658ee4562
libstdc++: Fix common_iterator::operator-> [PR95322]

This patch fixes the definition of common_iterator::operator-> when the
underlying iterator's operator* returns a non-reference.

The first problem is that the class __detail::_Common_iter_proxy is used
unqualified.  Fixing that revealed another problem: the class's template
friend declaration of common_iterator doesn't match up with the
definition of common_iterator, because the friend declaration isn't
constrained.

If we try to make the friend declaration match up by adding constraints,
we run into frontend bug PR93467.  So we currently can't correctly
express this friend relation between __detail::_Common_iter_proxy and
common_iterator.

As a workaround to this frontend bug, this patch moves the definition of
_Common_iter_proxy into the class template of common_iterator so that we
could instead express the friend relation via the injected-class-name.

(This bug was found when attempting to use views::common to work around
the compile failure with the testcase in PR95322.)

libstdc++-v3/ChangeLog:

PR libstdc++/95322
* include/bits/stl_iterator.h (__detail::_Common_iter_proxy):
Remove and instead define it ...
(common_iterator::_Proxy): ... here.
(common_iterator::operator->): Use it.
* testsuite/24_iterators/common_iterator/2.cc: New test.
* testsuite/std/ranges/adaptors/95322.cc: New test.

(cherry picked from commit 3bf5e7657b752cc2352778e8c20ac9cdddca4f93)
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/24_iterators/common_iterator/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc [new file with mode: 0644]