[all-commits] [llvm/llvm-project] 0a0e0a: [libc++] span: Fix incorrect static asserts

Louis Dionne via All-commits all-commits at lists.llvm.org
Fri Feb 14 05:33:09 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 0a0e0afaa0249a07b5d1609c433e991c8d982a73
      https://github.com/llvm/llvm-project/commit/0a0e0afaa0249a07b5d1609c433e991c8d982a73
  Author: Louis Dionne <ldionne at apple.com>
  Date:   2020-02-14 (Fri, 14 Feb 2020)

  Changed paths:
    M libcxx/include/span
    M libcxx/test/std/containers/views/span.elem/back.pass.cpp
    M libcxx/test/std/containers/views/span.elem/front.pass.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list