[libc++] span: Fix incorrect static asserts
authorLouis Dionne <ldionne@apple.com>
Fri, 14 Feb 2020 13:31:15 +0000 (14:31 +0100)
committerLouis Dionne <ldionne@apple.com>
Fri, 14 Feb 2020 13:32:41 +0000 (14:32 +0100)
commit0a0e0afaa0249a07b5d1609c433e991c8d982a73
tree8246aec51b1793193db98fefa0e0d074848c92bc
parent84240e0db8ab85b56df11e6cee8fef5ac7ee8c33
[libc++] span: Fix incorrect static asserts

The static asserts in span<T, N>::front() and span<T, N>::back() are
incorrect as they may be triggered from valid code due to evaluation
of a never taken branch:

    span<int, 0> foo;
    if (!foo.empty()) {
        auto x = foo.front();
    }

The problem is that the branch is always evaluated by the compiler,
creating invalid compile errors for span<T, 0>.

Thanks to Michael Schellenberger Costa for the patch.

Differential Revision: https://reviews.llvm.org/D71995
libcxx/include/span
libcxx/test/std/containers/views/span.elem/back.pass.cpp
libcxx/test/std/containers/views/span.elem/front.pass.cpp