public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112838] New: Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
@ 2023-12-03 20:10 eng.ahmad.nour at gmail dot com
  2023-12-03 20:27 ` [Bug c++/112838] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: eng.ahmad.nour at gmail dot com @ 2023-12-03 20:10 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-05 21:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-03 20:10 [Bug c++/112838] New: Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object eng.ahmad.nour at gmail dot com
2023-12-03 20:27 ` [Bug c++/112838] " pinskia at gcc dot gnu.org
2023-12-03 20:38 ` eng.ahmad.nour at gmail dot com
2023-12-03 20:53 ` pinskia at gcc dot gnu.org
2023-12-04 11:24 ` redi at gcc dot gnu.org
2023-12-04 11:30 ` redi at gcc dot gnu.org
2023-12-05  8:57 ` eng.ahmad.nour at gmail dot com
2023-12-05  9:01 ` eng.ahmad.nour at gmail dot com
2023-12-05 21:02 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).