<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - std::max_element causes an invalid static assert error in algorithm:2505:5: error: static_assert failed due to requirement '__is_forward_iterator<Iterator>::value' "std::max_element requires a ForwardIterator""
   href="https://bugs.llvm.org/show_bug.cgi?id=40698">40698</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::max_element causes an invalid static assert error in algorithm:2505:5: error: static_assert failed due to requirement '__is_forward_iterator<Iterator>::value' "std::max_element requires a ForwardIterator"
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vincent.lebourlot@starqube.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code generates a compilation error although the iterator being
marked as a forward iterator. This code compiles correctly on gcc 7.3.0.

~~~

#include <algorithm>

class Iterator:std::iterator<std::forward_iterator_tag,size_t>{
public:
        bool operator==(Iterator ter)const noexcept{return true;}
        bool operator!=(Iterator ter)const noexcept{return false;}
        Iterator operator++()const noexcept{return *this;}
        size_t operator*()const noexcept{return 42;}
};

int main(){
        Iterator begin,end;
        std::max_element(begin,end,[](size_t,size_t){return true;});
        return 0;
}

~~~

full error report: 

/usr/local/bin/clang++    -g -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
  -std=gnu++17 -o CMakeFiles/bug.dir/src/bug.cpp.o -c
CLionProjects/untitled/src/bug.cpp
In file included from CLionProjects/untitled/src/bug.cpp:1:
/usr/local/bin/../include/c++/v1/algorithm:2505:5: error: static_assert failed
due to requirement '__is_forward_iterator<Iterator>::value' "std::max_element
requires a ForwardIterator"
    static_assert(__is_forward_iterator<_ForwardIterator>::value,
    ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLionProjects/untitled/src/bug.cpp:13:7: note: in instantiation of function
template specialization 'std::__1::max_element<Iterator, (lambda at
CLionProjects/untitled/src/bug.cpp:13:29)>' requested here
        std::max_element(begin,end,[](size_t,size_t){return true;});</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>