[llvm-bugs] [Bug 37174] New: Wrong evaluation of constexpr function with loop

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 19 03:31:01 PDT 2018


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

            Bug ID: 37174
           Summary: Wrong evaluation of constexpr function with loop
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: morandidodo at gmail.com
                CC: llvm-bugs at lists.llvm.org

The following code does not compile with the trunk version (tested on godbolt
with the arguments: -std=c++17 -Wall -Wextra
--gcc-toolchain=/opt/compiler-explorer/gcc-snapshot)

#include <array>

template <typename Iter>
constexpr Iter
fun(Iter first, Iter last, Iter elem) {
    typename std::iterator_traits<Iter>::difference_type index = 1;
    for(auto iter = std::next(first); iter < last; /* missing increment here!
*/) {
        auto nextIter = std::next(iter, index + 1);

        if (iter >= last)
            return last;

        ++index;
        iter = nextIter;
    }

    return last;
}

constexpr bool
test() {
    std::array data {0, 1, 2, 3};    
    return fun(std::begin(data), std::end(data), std::next(std::begin(data),
2)) <= std::end(data);
}

static_assert(test());

I am not sure if the code could be simplified more than this to cause the bug.

-- 
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/20180419/c1b6cdd4/attachment.html>


More information about the llvm-bugs mailing list