[llvm-bugs] [Bug 40698] 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"

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 12 01:05:59 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40698

            Bug ID: 40698
           Summary: 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"
           Product: libc++
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vincent.lebourlot at starqube.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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;});

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190212/5db9d89c/attachment-0001.html>


More information about the llvm-bugs mailing list