[llvm-bugs] [Bug 34898] New: Constructors like std::vector::vector may be too liberal (or strict?) with conversions for non-input iterators

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 9 18:58:36 PDT 2017


            Bug ID: 34898
           Summary: Constructors like std::vector::vector may be too
                    liberal (or strict?) with conversions for non-input
           Product: libc++
           Version: 5.0
          Hardware: PC
               URL: https://godbolt.org/g/Vge69c
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dlj at google.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com


template <typename CategoryT>
class Iterator : public boost::iterator_facade<Iterator<CategoryT>, Base,
CategoryT> {
  friend class boost::iterator_core_access;
  void increment();
  bool equal(Iterator const& other) const;
  typename Iterator::reference dereference() const;

void foo() {
  using ForwardIt = Iterator<std::forward_iterator_tag>;
  std::vector<Derived> x1(ForwardIt{}, ForwardIt{});

  using InputIt = Iterator<std::input_iterator_tag>;
  std::vector<Derived> x2(InputIt{}, InputIt{}); // ERROR


The example is a bit complex, but the upshot is that
`std::vector::vector(Iterator, Iterator)` uses push_back() only for input
iterators. This is in contrast with forward iterators or greater, which use
emplacement, and thus consider the explicit constructors.

The standard would indicate that libc++'s InputIterator behaviour is correct.
Specifically, it gives this example:

X(i, j)
Requires:  T shall be EmplaceConstructible into X from *i. [...]


with the constraint:

"... i and j denote iterators satisfying input iterator requirements and refer
to elements implicitly convertible to value_­type ..."


This means that constructing a vector from iterator inputs, and using explicit
constructors, is undefined behaviour.

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/20171010/b639c58d/attachment.html>

More information about the llvm-bugs mailing list