<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Constructors like std::vector::vector may be too liberal (or strict?) with conversions for non-input iterators"
   href="https://bugs.llvm.org/show_bug.cgi?id=34898">34898</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Constructors like std::vector::vector may be too liberal (or strict?) with conversions for non-input iterators
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>URL</th>
          <td>https://godbolt.org/g/Vge69c
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dlj@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example:

=====
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
}
=====


<a href="https://godbolt.org/g/Vge69c">https://godbolt.org/g/Vge69c</a>

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. [...]

<a href="https://timsong-cpp.github.io/cppwp/n4659/container.requirements#tab:containers.sequence.requirements">https://timsong-cpp.github.io/cppwp/n4659/container.requirements#tab:containers.sequence.requirements</a>

with the constraint:

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

<a href="https://timsong-cpp.github.io/cppwp/n4659/container.requirements#sequence.reqmts-3">https://timsong-cpp.github.io/cppwp/n4659/container.requirements#sequence.reqmts-3</a>


This means that constructing a vector from iterator inputs, and using explicit
constructors, is undefined behaviour.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>