[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
https://bugs.llvm.org/show_bug.cgi?id=34898
Bug ID: 34898
Summary: Constructors like std::vector::vector may be too
liberal (or strict?) with conversions for non-input
iterators
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
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
}
=====
https://godbolt.org/g/Vge69c
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. [...]
https://timsong-cpp.github.io/cppwp/n4659/container.requirements#tab:containers.sequence.requirements
with the constraint:
"... i and j denote iterators satisfying input iterator requirements and refer
to elements implicitly convertible to value_type ..."
https://timsong-cpp.github.io/cppwp/n4659/container.requirements#sequence.reqmts-3
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