[llvm-bugs] [Bug 44725] New: [span] Incorrect static_assert in span::front and span::back

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 31 01:33:11 PST 2020


            Bug ID: 44725
           Summary: [span] Incorrect static_assert in span::front and
           Product: libc++
           Version: 10.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mschellenbergercosta at googlemail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Currently ```span<T, extent>::front()``` and ```span<T, extent>::back()``` have
a static_assert that checks whether ```extent > 0```.

However, this is an invalid requirement, as it would trigger in all evaluated
branches. Consider the following code

template<class R>
int get_front_or_default(R myRange, int myDefault) {
    if (!myRange.empty()) 
       return myRange.front();
       return myDefault; 

This would give a compile error when passed a span<int, 0> albeit the front()
method is never called. Consequently, the static_assert should be replaced by

There is already a PR for that (https://reviews.llvm.org/D71995)

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/20200131/e522f686/attachment.html>

More information about the llvm-bugs mailing list