public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eng.ahmad.nour at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/112838] New: Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
Date: Sun, 03 Dec 2023 20:10:25 +0000	[thread overview]
Message-ID: <bug-112838-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2023-12-03 20:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-03 20:10 eng.ahmad.nour at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-112838-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).