https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61587
Bug ID: 61587 Summary: Line number of code that triggers "use of deleted function" error is absent from error message Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: Marc.van-Leeuwen at math dot univ-poitiers.fr Created attachment 32987 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=32987&action=edit preprocessed source code triggering error The following C++11 code contains an error in the declaration "A a2(a1);" in line 18, two lines before the end (with "a1" replaced by "std::move(a1)" in that line, the code compiles correctly). The kind of error that was found is correctly (if not very succinctly) indicated in the error message, but the location of the error is not. ------------------------------------------------------------ #include <vector> #include <memory> typedef std::unique_ptr<int> U_ptr; class A { std::vector<U_ptr> v; public: void add(U_ptr&& b) { v.emplace_back(std::move(b)); } }; void f() { A a1; U_ptr p(new int(123)); a1.add(std::move(p)); a1.add(U_ptr(new int(4567))); // unnamed argument does not need std::move A a2(a1); // the error is here a2.add(U_ptr(std::move(new int(17)))); } -------------------------------------------------------------- Compile commend g++ -std=c++11 -c -o mini.o mini.cpp Below are the error messages generated; note that the only lines in the source file mini.cpp that are referenced are lines 1,2,6 which does not go beyond the class definition of A. There is no way to deduce from the error message that the compiler was busy compiling the function f() when this error was triggered, even less where in that function the error is triggered. Since the code before the definition of f() is perfectly fine, this is obviouly very unhelpful in actually finding the error. Error messages: In file included from /usr/include/c++/4.8/vector:62:0, from mini.cpp:1: /usr/include/c++/4.8/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = std::unique_ptr<int>; _Args = {const std::unique_ptr<int, std::default_delete<int> >&}]’: /usr/include/c++/4.8/bits/stl_uninitialized.h:75:53: required from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::unique_ptr<int>*, std::vector<std::unique_ptr<int> > >; _ForwardIterator = std::unique_ptr<int>*; bool _TrivialValueTypes = false]’ /usr/include/c++/4.8/bits/stl_uninitialized.h:117:41: required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::unique_ptr<int>*, std::vector<std::unique_ptr<int> > >; _ForwardIterator = std::unique_ptr<int>*]’ /usr/include/c++/4.8/bits/stl_uninitialized.h:258:63: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::unique_ptr<int>*, std::vector<std::unique_ptr<int> > >; _ForwardIterator = std::unique_ptr<int>*; _Tp = std::unique_ptr<int>]’ /usr/include/c++/4.8/bits/stl_vector.h:316:32: required from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::unique_ptr<int>; _Alloc = std::allocator<std::unique_ptr<int> >]’ mini.cpp:6:7: required from here /usr/include/c++/4.8/bits/stl_construct.h:75:7: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’ { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); } ^ In file included from /usr/include/c++/4.8/memory:81:0, from mini.cpp:2: /usr/include/c++/4.8/bits/unique_ptr.h:273:7: error: declared here unique_ptr(const unique_ptr&) = delete; ^