From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26952 invoked by alias); 14 Jan 2013 20:51:52 -0000 Received: (qmail 26730 invoked by uid 48); 14 Jan 2013 20:51:30 -0000 From: "daniel.kruegler at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/55977] New: [C++11] vector range construction imposes unnecessary conversion constraints Date: Mon, 14 Jan 2013 20:51:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.kruegler at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg01234.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55977 Bug #: 55977 Summary: [C++11] vector range construction imposes unnecessary conversion constraints Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: daniel.kruegler@googlemail.com The following code compiled with gcc 4.8.0 20130113 (experimental) using the flags -Wall -std=c++11 -pedantic is rejected: //------------------------------------- #include #include #include #include #include template struct MyAllocator { std::allocator base; typedef T value_type; MyAllocator() = default; template MyAllocator(const MyAllocator& other) : base(other.base) {} T* allocate(std::size_t n) { return base.allocate(n); } void deallocate(T* p, std::size_t n) { return base.deallocate(p, n); } template void construct(U* p, Args&&... args) { ::new (static_cast(p)) T(std::forward(args)...); } }; struct A { private: friend class MyAllocator; A(int value) : value(value) {} int value; public: A() : value() {} int get() const { return value; } }; int main() { std::vector> v1; const int i = 1; v1.emplace_back(i); // OK std::vector> v2(std::istream_iterator(std::cin), {}); // Error } //------------------------------------- "[..]gcc\include\c++\4.8.0\bits\stl_vector.h||In instantiation of 'void std::vector<_Tp, _Alloc>::_M_range_initialize(_InputIterator, _InputIterator, std::input_iterator_tag) [with _InputIterator = std::istream_iterator; _Tp = A; _Alloc = MyAllocator]':| [..]gcc\include\c++\4.8.0\bits\stl_vector.h|1178|required from 'void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_InputIterator, _InputIterator, std::__false_type) [with _InputIterator = std::istream_iterator; _Tp = A; _Alloc = MyAllocator]'| [..]gcc\include\c++\4.8.0\bits\stl_vector.h|396|required from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = std::istream_iterator; = void; _Tp = A; _Alloc = MyAllocator; std::vector<_Tp, _Alloc>::allocator_type = MyAllocator]'| main.cpp|38|required from here| main.cpp|26|error: 'A::A(int)' is private| [..]gcc\include\c++\4.8.0\bits\stl_vector.h|1188|error: within this context" The error is due to a call of push_back with an previous int->A conversion. Such an conversion from the iterator's value_type to the containers value_type is not feasible. The specification of the corresponding constructor is (indirectly) ruled by Table 100, expression X(i, j): "Requires: T shall be EmplaceConstructible into X from *i." Move/CopyConstructible or Convertible to value_type are not required. Instead of invoking push_back this constructor should internally invoke the equivalent of emplace_back. The same problem also occurs for other standard containers such as std::list.