This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/78830] New: std::prev accepts ForwardIterator-s


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]