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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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 ` pinskia at gcc dot gnu.org
  2023-12-03 20:38 ` eng.ahmad.nour at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-03 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-12-03
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, I thought I had saw an issue filed that is very smilar to this.


Note clang provides the context:

<source>:5:7: note: in instantiation of member function
'std::vector<std::unique_ptr<int>>::vector' requested here
    5 | class NonCopyable
      |       ^
<source>:14:18: note: in implicit copy constructor for 'NonCopyable' first
required here
   14 |         NonCopyable b(a);
      |                     ^

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: eng.ahmad.nour at gmail dot com @ 2023-12-03 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Ahmad Nour <eng.ahmad.nour at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> Confirmed, I thought I had saw an issue filed that is very smilar to this.
> 
> 
> Note clang provides the context:
> 
> <source>:5:7: note: in instantiation of member function
> 'std::vector<std::unique_ptr<int>>::vector' requested here
>     5 | class NonCopyable
>       |       ^
> <source>:14:18: note: in implicit copy constructor for 'NonCopyable' first
> required here
>    14 |         NonCopyable b(a);
>       |                     ^

Thanks for confirmation.
I tried with clang-12 -Wall -Wextra main.cpp, but I didn't get that hint/note.
Am I missing something?

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-03 20:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Ahmad Nour from comment #2)
> 
> Thanks for confirmation.
> I tried with clang-12 -Wall -Wextra main.cpp, but I didn't get that
> hint/note. Am I missing something?

Oh I tried with -std=c++20 which provided that note.  Sorry about that. But it
might be the case that adding this for -std=c++17 might be hard ...

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-04 11:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Confirmed, I thought I had saw an issue filed that is very smilar to this.

See PR 80858 (and PR 58589) and PR 106176 and PR 90413 and others.

I created PR 109551 for the underlying front-end issue.

*** This bug has been marked as a duplicate of bug 109551 ***

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-04 11:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Ahmad Nour from comment #2)
> I tried with clang-12 -Wall -Wextra main.cpp, but I didn't get that
> hint/note. Am I missing something?

You should get that note with clang-12 (and newer versions)
https://godbolt.org/z/KM65MKrPa

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: eng.ahmad.nour at gmail dot com @ 2023-12-05  8:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Ahmad Nour <eng.ahmad.nour at gmail dot com> ---
(In reply to Jonathan Wakely from comment #5)
> (In reply to Ahmad Nour from comment #2)
> > I tried with clang-12 -Wall -Wextra main.cpp, but I didn't get that
> > hint/note. Am I missing something?
> 
> You should get that note with clang-12 (and newer versions)
> https://godbolt.org/z/KM65MKrPa

Thanks, but I also don't see it in godbolt output.
Note: I'm referring to this exact note:

> <source>:14:18: note: in implicit copy constructor for 'NonCopyable' first required here
>    14 |         NonCopyable b(a);

I can't find anything related to line #13: NonCopyable b(a); which is the root
cause of the issue

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: eng.ahmad.nour at gmail dot com @ 2023-12-05  9:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Ahmad Nour <eng.ahmad.nour at gmail dot com> ---
(In reply to Andrew Pinski from comment #3)
> (In reply to Ahmad Nour from comment #2)
> > 
> > Thanks for confirmation.
> > I tried with clang-12 -Wall -Wextra main.cpp, but I didn't get that
> > hint/note. Am I missing something?
> 
> Oh I tried with -std=c++20 which provided that note.  Sorry about that. But
> it might be the case that adding this for -std=c++17 might be hard ...

Hmmmmm this is what I'm getting with c++20. I can't find that note where it
points to line #13

>> clang-12 -Wall -Wextra main.cpp -std=c++20
In file included from main.cpp:1:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/vector:66:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:137:7:
error: static_assert failed due to requirement
'is_constructible<std::unique_ptr<int, std::default_delete<int>>, const
std::unique_ptr<int, std::default_delete<int>> &>::value' "result type must be
constructible from value type of input range"
      static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
      ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:325:19:
note: in instantiation of function template specialization
'std::uninitialized_copy<__gnu_cxx::__normal_iterator<const
std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>,
std::unique_ptr<int> *>' requested here
    { return std::uninitialized_copy(__first, __last, __result); }
                  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:558:9:
note: in instantiation of function template specialization
'std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<const
std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>,
std::unique_ptr<int> *, std::unique_ptr<int>>' requested here
          std::__uninitialized_copy_a(__x.begin(), __x.end(),
               ^
main.cpp:4:7: note: in instantiation of member function
'std::vector<std::unique_ptr<int>>::vector' requested here
class NonCopyable
      ^
In file included from main.cpp:1:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/vector:62:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:62:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_tempbuf.h:60:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_construct.h:109:38:
error: call to deleted constructor of 'std::unique_ptr<int>'
    { ::new(static_cast<void*>(__p)) _Tp(std::forward<_Args>(__args)...); }
                                     ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:91:8:
note: in instantiation of function template specialization
'std::_Construct<std::unique_ptr<int>, const std::unique_ptr<int> &>' requested
here
                std::_Construct(std::__addressof(*__cur), *__first);
                     ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:150:2:
note: in instantiation of function template specialization
'std::__uninitialized_copy<false>::__uninit_copy<__gnu_cxx::__normal_iterator<const
std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>,
std::unique_ptr<int> *>' requested here
        __uninit_copy(__first, __last, __result);
        ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_uninitialized.h:325:19:
note: in instantiation of function template specialization
'std::uninitialized_copy<__gnu_cxx::__normal_iterator<const
std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>,
std::unique_ptr<int> *>' requested here
    { return std::uninitialized_copy(__first, __last, __result); }
                  ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_vector.h:558:9:
note: in instantiation of function template specialization
'std::__uninitialized_copy_a<__gnu_cxx::__normal_iterator<const
std::unique_ptr<int> *, std::vector<std::unique_ptr<int>>>,
std::unique_ptr<int> *, std::unique_ptr<int>>' requested here
          std::__uninitialized_copy_a(__x.begin(), __x.end(),
               ^
main.cpp:4:7: note: in instantiation of member function
'std::vector<std::unique_ptr<int>>::vector' requested here
class NonCopyable
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/unique_ptr.h:468:7:
note: 'unique_ptr' has been explicitly marked deleted here
      unique_ptr(const unique_ptr&) = delete;
      ^
2 errors generated.

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

* [Bug c++/112838] Compiler is unable to show the exact error location when calling copy ctor for a non-copyable object
  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
                   ` (6 preceding siblings ...)
  2023-12-05  9:01 ` eng.ahmad.nour at gmail dot com
@ 2023-12-05 21:02 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-05 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Ahmad Nour from comment #7)
> (In reply to Andrew Pinski from comment #3)
> > (In reply to Ahmad Nour from comment #2)
> > > 
> > > Thanks for confirmation.
> > > I tried with clang-12 -Wall -Wextra main.cpp, but I didn't get that
> > > hint/note. Am I missing something?
> > 
> > Oh I tried with -std=c++20 which provided that note.  Sorry about that. But
> > it might be the case that adding this for -std=c++17 might be hard ...
> 
> Hmmmmm this is what I'm getting with c++20. I can't find that note where it
> points to line #13
> 
> >> clang-12 -Wall -Wextra main.cpp -std=c++20

well clang-12 was released 2 years ago ... I am trying to say that clang
already fixed this case for -std=c++20 in a newer clang version and GCC should
fix this too, that is what PR 109551 is about.  Note compiler developers tend
to try to the trunk (mainline) sources of each compiler to see if what other
compilers do and don't really look into older releases of the other compiler to
see when it was added especially when it comes to diagnostic improvments.

^ 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).