gcc/libstdc++-v3/include/std
Patrick Palka afb8da7faa libstdc++: Don't initialize from *this inside some views [PR97600]
This works around a subtle issue where instantiating the begin()/end()
member of some views (as part of return type deduction) inadvertently
requires computing the satisfaction value of range<foo_view>.

This is problematic because the constraint range<foo_view> requires the
begin()/end() member to be callable.  But it's not callable until we've
deduced its return type, so evaluation of range<foo_view> yields false
at this point.  And if after both members are instantiated (and their
return types deduced) we evaluate range<foo_view> again, this time it
will yield true since the begin()/end() members are now both callable.
This makes the program ill-formed according to [temp.constr.atomic]/3:

  If, at different points in the program, the satisfaction result is
  different for identical atomic constraints and template arguments, the
  program is ill-formed, no diagnostic required.

The views affected by this issue are those whose begin()/end() member
has a placeholder return type and that member initializes an _Iterator
or _Sentinel object from a reference to *this.  The second condition is
relevant because it means explicit conversion functions are considered
during overload resolution (as per [over.match.copy], I think), and
therefore it causes g++ to check the constraints of the conversion
function view_interface<foo_view>::operator bool().  And this conversion
function's constraints indirectly require range<foo_view>.

This issue is observable on trunk only with basic_istream_view (as in
the testcase in the PR).  But a pending patch that makes g++ memoize
constraint satisfaction values indefinitely (it currently invalidates
the satisfaction cache on various events) causes many existing tests for
the other affected views to fail, because range<foo_view> then remains
false for the whole compilation.

This patch works around this issue by adjusting the constructors of the
_Iterator and _Sentinel types of the affected views to take their
foo_view argument by pointer instead of by reference, so that g++ no
longer considers explicit conversion functions when resolving the
direct-initialization inside these views' begin()/end() members.

libstdc++-v3/ChangeLog:

	PR libstdc++/97600
	* include/std/ranges (basic_istream_view::begin): Initialize
	_Iterator from 'this' instead of '*this'.
	(basic_istream_view::_Iterator::_Iterator): Adjust constructor
	accordingly.
	(filter_view::_Iterator::_Iterator): Take a filter_view*
	argument instead of a filter_view& argument.
	(filter_view::_Sentinel::_Sentinel): Likewise.
	(filter_view::begin): Initialize _Iterator from 'this' instead
	of '*this'.
	(filter_view::end): Likewise.
	(transform_view::_Iterator::_Iterator): Take a _Parent* instead
	of a _Parent&.
	(filter_view::_Iterator::operator+): Adjust accordingly.
	(filter_view::_Iterator::operator-): Likewise.
	(filter_view::begin): Initialize _Iterator from 'this' instead
	of '*this'.
	(filter_view::end): Likewise.
	(join_view::_Iterator): Take a _Parent* instead of a _Parent&.
	(join_view::_Sentinel): Likewise.
	(join_view::begin): Initialize _Iterator from 'this' instead of
	'*this'.
	(join_view::end): Initialize _Sentinel from 'this' instead of
	'*this'.
	(split_view::_OuterIter): Take a _Parent& instead of a _Parent*.
	(split_view::begin): Initialize _OuterIter from 'this' instead
	of '*this'.
	(split_view::end): Likewise.
	* testsuite/std/ranges/97600.cc: New test.
2020-10-30 20:33:19 -04:00
..
algorithm libstdc++: Implement C++20 constrained algorithms 2020-02-06 20:08:34 -05:00
any libstdc++: Fix constructor constraints for std::any (PR 90415) 2020-04-24 00:54:20 +01:00
array libstdc++: Fix three-way comparison for std::array [PR 96851] 2020-09-02 15:32:11 +01:00
atomic libstdc++: Break long lines to fit in 80 columns 2020-08-05 22:48:17 +01:00
bit libstdc++: Replace __int_limits with __numeric_traits_integer 2020-07-07 23:36:29 +01:00
bitset libstdc++: Add comparison operators to types from Utilities clause 2020-04-15 19:47:48 +01:00
charconv libstdc++: Add missing noexcept to std::from_chars declarations 2020-10-27 14:50:38 +00:00
chrono libstdc++: Fix arithmetic bug in year_month_weekday conversion [PR96713] 2020-10-28 12:28:08 -04:00
codecvt
complex libstdc++: Fix -Wmismatched-tags warnings (PR 96063) 2020-07-06 17:12:29 +01:00
concepts libstdc++: Fix typos in copyright notice 2020-10-15 19:20:21 +01:00
condition_variable libstdc++: Reduce header dependencies in and on <memory> 2020-10-22 18:42:03 +01:00
coroutine libstdc++: Define noop coroutine details private and inline [PR 95917] 2020-10-20 11:37:48 +01:00
deque libstdc++: Update __cpp_lib_erase_if macro (P1115R3) 2020-02-15 10:25:23 +00:00
execution libstdc++: Define __cpp_lib_execution feature test macro 2020-04-22 22:54:35 +01:00
filesystem Update copyright years. 2020-01-01 12:51:42 +01:00
forward_list libstdc++: Update __cpp_lib_erase_if macro (P1115R3) 2020-02-15 10:25:23 +00:00
fstream libstdc++: Override BUFSIZ for Windows targets [PR 94268] 2020-10-28 13:19:21 +00:00
functional libstdc++: Fix ODR violations caused by <tr1/functional> 2020-10-27 16:32:53 +00:00
future libstdc++: Reduce header dependencies in and on <memory> 2020-10-22 18:42:03 +01:00
iomanip Update copyright years. 2020-01-01 12:51:42 +01:00
ios Update copyright years. 2020-01-01 12:51:42 +01:00
iosfwd Update copyright years. 2020-01-01 12:51:42 +01:00
iostream Update copyright years. 2020-01-01 12:51:42 +01:00
istream libstdc++: Adjust overflow prevention to operator>> 2020-08-06 18:26:45 +01:00
iterator Update copyright years. 2020-01-01 12:51:42 +01:00
limits libstdc++: Make __int128 meet integer-class requirements [PR 96042] 2020-08-19 16:49:07 +01:00
list libstdc++: Update __cpp_lib_erase_if macro (P1115R3) 2020-02-15 10:25:23 +00:00
locale
map Update copyright years. 2020-01-01 12:51:42 +01:00
memory libstdc++: Reduce header dependencies in and on <memory> 2020-10-22 18:42:03 +01:00
memory_resource libstdc++: Ensure std::forward_as_tuple is defined 2020-10-23 01:12:00 +01:00
mutex libstdc++: Define and use chrono::is_clock for C++20 2020-03-25 22:07:02 +00:00
numbers Update copyright years. 2020-01-01 12:51:42 +01:00
numeric libstdc++: Minor header cleanup in <numeric> 2020-10-05 22:46:46 +01:00
optional libstdc++: Cleanup whitespace and type trait usage in <optional> 2020-07-06 21:55:50 +01:00
ostream Update copyright years. 2020-01-01 12:51:42 +01:00
queue Update copyright years. 2020-01-01 12:51:42 +01:00
random Update copyright years. 2020-01-01 12:51:42 +01:00
ranges libstdc++: Don't initialize from *this inside some views [PR97600] 2020-10-30 20:33:19 -04:00
ratio
regex libstdc++: Reduce uses of std::numeric_limits 2020-10-06 00:05:11 +01:00
scoped_allocator libstdc++: Reduce header dependencies in and on <memory> 2020-10-22 18:42:03 +01:00
set Update copyright years. 2020-01-01 12:51:42 +01:00
shared_mutex libstdc++: Only include <condition_variable> in <shared_mutex> if needed 2020-10-22 18:49:38 +01:00
span libstdc++: Make std::span layout-compatible with struct iovec [PR 95609] 2020-10-28 12:07:40 +00:00
sstream libstdc++: Fix new basic_stringbuf constructor 2020-10-29 01:28:12 +00:00
stack Update copyright years. 2020-01-01 12:51:42 +01:00
stdexcept Update copyright years. 2020-01-01 12:51:42 +01:00
stop_token libstdc++: Fix <stop_token> to compile without gthreads 2020-08-11 16:16:21 +01:00
streambuf libstdc++: Add deprecated attributes to old iostream members 2020-08-19 12:13:23 +01:00
string libstdc++: Update __cpp_lib_erase_if macro (P1115R3) 2020-02-15 10:25:23 +00:00
string_view libstdc++: Reduce uses of std::numeric_limits 2020-10-06 00:05:11 +01:00
system_error libstdc++: Fix -Wmismatched-tags warnings (PR 96063) 2020-07-06 17:12:29 +01:00
thread libstdc++: Remove redundant copying of std::async arguments [PR 69724] 2020-08-18 14:28:38 +01:00
tuple libstdc++: Use reserved name for C++20 attribute 2020-10-19 18:07:21 +01:00
type_traits c++: Implement __is_nothrow_constructible and __is_nothrow_assignable 2020-10-26 15:36:24 +02:00
typeindex libstdc++: Add spaceship operator to std::type_index 2020-04-15 19:47:47 +01:00
unordered_map Update copyright years. 2020-01-01 12:51:42 +01:00
unordered_set Update copyright years. 2020-01-01 12:51:42 +01:00
utility libstdc++: Replace __int_limits with __numeric_traits_integer 2020-07-07 23:36:29 +01:00
valarray libstdc++: Fix -Wmismatched-tags warnings (PR 96063) 2020-07-06 17:12:29 +01:00
variant libstdc++: Fix some warnings in headers 2020-10-29 22:47:22 +00:00
vector libstdc++: Update __cpp_lib_erase_if macro (P1115R3) 2020-02-15 10:25:23 +00:00
version libstdc++: Only include <condition_variable> in <shared_mutex> if needed 2020-10-22 18:49:38 +01:00