[Bug libstdc++/78830] New: std::prev accepts ForwardIterator-s
akrzemi1 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Dec 16 08:03:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78830
Bug ID: 78830
Summary: std::prev accepts ForwardIterator-s
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: akrzemi1 at gmail dot com
Target Milestone: ---
The following code compiles, even though according to the C++ Standard it is
ill-formed.
```
#include <forward_list>
#include <algorithm>
int main()
{
std::forward_list<int> il = {1, 2, 3, 4, 5, 6, 7};
auto iter = std::prev(il.end());
}
```
While the fix for 62039 mitigates the problem, according to the Standard this
code should be rejected unconditionally. Clang does this by using enable_if
trick. A static_assert would also work.
More information about the Gcc-bugs
mailing list