[all-commits] [llvm/llvm-project] d27cbf: [libc++] Fix bug in ranges::advance

Louis Dionne via All-commits all-commits at lists.llvm.org
Thu Jan 27 07:58:15 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d27cbfa9d366c2f6620770f514f612aa1bb0ecb6
      https://github.com/llvm/llvm-project/commit/d27cbfa9d366c2f6620770f514f612aa1bb0ecb6
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2022-01-27 (Thu, 27 Jan 2022)

  Changed paths:
    M libcxx/include/__iterator/advance.h
    M libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
    M libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp

  Log Message:
  -----------
  [libc++] Fix bug in ranges::advance

In `ranges::advance(iter, n, bound)`, we'd incorrectly handle the case
where bound < iter and n is 0:

    int a[10];
    int *p = a+5;
    int *bound = a+3;
    std::ranges::advance(p, 0, bound);
    assert(p - a == 5); // we'd return 3 before this patch

This was caused by an incorrect handling of 0 inside __magnitude_geq.

Differential Revision: https://reviews.llvm.org/D117240




More information about the All-commits mailing list