https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100770
Bug ID: 100770
Summary: Incorrect if constexpr statement in
ranges::unique_copy
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
In ranges::unique_copy in ranges_algo.h#L1435:
else if constexpr (input_iterator<_Out>
&& same_as<iter_value_t<_Iter>, iter_value_t<_Out>>)
Since there is no short circuit in if constexpr statement, this will
incorrectly abort compilation when iter_value_t<_Out> is ill-formed.
(thanks T.C. for pointing that out).
#include <algorithm>
#include <iostream>
#include <sstream>
int main() {
std::istringstream str("42 42 42");
std::ranges::unique_copy(
std::istream_iterator<int>(str),
std::istream_iterator<int>(),
std::ostream_iterator<int>(std::cout, " "));
}
https://godbolt.org/z/PM58b3KrE