https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112838

            Bug ID: 112838
           Summary: Compiler is unable to show the exact error location
                    when calling copy ctor for a non-copyable object
           Product: gcc
           Version: 10.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eng.ahmad.nour at gmail dot com
  Target Milestone: ---

For this minimal example, the compiler never shows that the "real" cause of the
error is line #13 where the copy ctor is being called.

01    #include <vector>
02    #include <memory>
03    
04    class NonCopyable
05    {
06    private:
07        std::vector<std::unique_ptr<int>> mElements;
08    };
09    
10    int main()
11    {
12      NonCopyable a;
13      NonCopyable b(a);
14      
15      return 0;
16    }


I'm compiling using: 
g++-10 -Wall -Wextra main.cpp

And getting this:
In file included from /usr/include/c++/10/vector:66,
                 from main.cpp:1:
/usr/include/c++/10/bits/stl_uninitialized.h: In instantiation of
‘_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++/10/bits/stl_uninitialized.h:325:37:   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++/10/bits/stl_vector.h:558:31:   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> >]’
main.cpp:4:7:   required from here
/usr/include/c++/10/bits/stl_uninitialized.h:137:72: error: static assertion
failed: result type must be constructible from value type of input range
  137 |       static_assert(is_constructible<_ValueType2,
decltype(*__first)>::value,
      |                                                                       
^~~~~

Compiler only shows that error is related to the class NonCopyable. But it was
a nightmare for me to try and find the exact line where copying was made in the
whole project.

Reply via email to