public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61587] New: Line number of code that triggers "use of deleted function" error is absent from error message
@ 2014-06-23 15:10 Marc.van-Leeuwen at math dot univ-poitiers.fr
  2014-06-23 17:08 ` [Bug c++/61587] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Marc.van-Leeuwen at math dot univ-poitiers.fr @ 2014-06-23 15:10 UTC (permalink / raw)
  To: gcc-bugs

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;
       ^
>From gcc-bugs-return-454709-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jun 23 15:11:22 2014
Return-Path: <gcc-bugs-return-454709-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 2627 invoked by alias); 23 Jun 2014 15:11:21 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 2559 invoked by uid 55); 23 Jun 2014 15:11:15 -0000
From: "amodra at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/61583] [4.9/4.10 regression] stage2 and stage3 compare failure due to value range loss
Date: Mon, 23 Jun 2014 15:11:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: bootstrap
X-Bugzilla-Version: 4.9.1
X-Bugzilla-Keywords: build
X-Bugzilla-Severity: normal
X-Bugzilla-Who: amodra at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: amodra at gmail dot com
X-Bugzilla-Target-Milestone: 4.9.1
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-61583-4-AXjL9V9aIa@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61583-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61583-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-06/txt/msg01791.txt.bz2
Content-length: 641

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida583

--- Comment #4 from Alan Modra <amodra at gcc dot gnu.org> ---
Author: amodra
Date: Mon Jun 23 15:10:32 2014
New Revision: 211898

URL: https://gcc.gnu.org/viewcvs?rev!1898&root=gcc&view=rev
Log:
gcc/
    PR bootstrap/61583
    * tree-vrp.c (remove_range_assertions): Do not set is_unreachable
    to zero on debug statements.
gcc/testsuite/
    * gcc.dg/pr61583.c: New.


Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/pr61583.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_9-branch/gcc/tree-vrp.c


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

* [Bug c++/61587] Line number of code that triggers "use of deleted function" error is absent from error message
  2014-06-23 15:10 [Bug c++/61587] New: Line number of code that triggers "use of deleted function" error is absent from error message Marc.van-Leeuwen at math dot univ-poitiers.fr
@ 2014-06-23 17:08 ` redi at gcc dot gnu.org
  2014-06-24  3:40 ` Marc.van-Leeuwen at math dot univ-poitiers.fr
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2014-06-23 17:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Your type's copy constructor is implicitly-declared, so there is no exact line
number to point to. That's why it points to the class definition at line 6


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

* [Bug c++/61587] Line number of code that triggers "use of deleted function" error is absent from error message
  2014-06-23 15:10 [Bug c++/61587] New: Line number of code that triggers "use of deleted function" error is absent from error message Marc.van-Leeuwen at math dot univ-poitiers.fr
  2014-06-23 17:08 ` [Bug c++/61587] " redi at gcc dot gnu.org
@ 2014-06-24  3:40 ` Marc.van-Leeuwen at math dot univ-poitiers.fr
  2014-06-24  8:21 ` redi at gcc dot gnu.org
  2021-12-02 23:47 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: Marc.van-Leeuwen at math dot univ-poitiers.fr @ 2014-06-24  3:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marc van Leeuwen <Marc.van-Leeuwen at math dot univ-poitiers.fr> ---
But the error in this program is so much not with the implicitly declared copy
constructor of A itself (I suppose it is "A::A (const &A)" that the compiler is
trying to generate here) but with the fact that the code is (accidentally)
_using_ that copy constructor. That usage in done in the indicated line 18, and
without that line the program compiles correctly. I agree that it might have
been better to explicitly mark that implicitly-declared copy constructor as
deleted in the class definition of A, but one does not _have to_ do that, as
long as such a copy constructor is not being used anywhere.

So the compiler must have been reading at least up to line 18 before it decided
to emit this error message; my complaint is just that _nothing_ in the list of
error message gies any indication of that. I would think C++ compilation is
basically a single-pass process, and that it would be rather easy for a
compiler to start (or end) each error message with an indication of exactly
where it is during this pass; in my experience with gcc such an indication
sometimes comes in the middle of a long sequence of messages, which is fine
with me too, but in this particular case such indication seems to be entirely
absent.

In practice such illegal copy-constructing of an A object could happen in code
very far from the class definition; how is a user going to trace the place
where she did so?


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

* [Bug c++/61587] Line number of code that triggers "use of deleted function" error is absent from error message
  2014-06-23 15:10 [Bug c++/61587] New: Line number of code that triggers "use of deleted function" error is absent from error message Marc.van-Leeuwen at math dot univ-poitiers.fr
  2014-06-23 17:08 ` [Bug c++/61587] " redi at gcc dot gnu.org
  2014-06-24  3:40 ` Marc.van-Leeuwen at math dot univ-poitiers.fr
@ 2014-06-24  8:21 ` redi at gcc dot gnu.org
  2021-12-02 23:47 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2014-06-24  8:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-06-24
     Ever confirmed|0                           |1

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

template<typename T>
struct vector {
  T t;
  vector(const vector& v) : t(v.t) { }
  vector() { }
};

struct U_ptr {
  U_ptr() = default;
  U_ptr(U_ptr&&) = default;
};

class A {
  vector<U_ptr> v;
};

void f() {
    A a1;
    A a2(a1); // the error is here
}

Compiling with -std=c++11 gives:

r.cc: In instantiation of ‘vector<T>::vector(const vector<T>&) [with T =
U_ptr]’:
r.cc:13:7:   required from here
r.cc:4:34: error: use of deleted function ‘constexpr U_ptr::U_ptr(const
U_ptr&)’
   vector(const vector& v) : t(v.t) { }
                                  ^
r.cc:8:8: note: ‘constexpr U_ptr::U_ptr(const U_ptr&)’ is implicitly declared
as deleted because ‘U_ptr’ declares a move constructor or move assignment
operator
 struct U_ptr {
        ^


Not a regression.

Clang gives very similar output, without pointing to the invalid copy
construction.

EDG says the error happens due to the implicit generation of A's copy
constructor at line 19.
>From gcc-bugs-return-454761-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Jun 24 08:23:02 2014
Return-Path: <gcc-bugs-return-454761-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 4283 invoked by alias); 24 Jun 2014 08:23:02 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 3608 invoked by uid 48); 24 Jun 2014 08:22:55 -0000
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/61572] [4.10 Regression] ICE: in assign_by_spills, at lra-assigns.c:1335
Date: Tue, 24 Jun 2014 08:23:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 4.10.0
X-Bugzilla-Keywords: ra
X-Bugzilla-Severity: normal
X-Bugzilla-Who: rguenth at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.10.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-61572-4-75wjtapQ4M@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61572-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61572-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-06/txt/msg01843.txt.bz2
Content-length: 590

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida572

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bonzini at gnu dot org,
                   |                            |zadeck at gcc dot gnu.org

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The question of course is why rdx is live from function entry to its first use.
My patch will only continue to paper over this issue.


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

* [Bug c++/61587] Line number of code that triggers "use of deleted function" error is absent from error message
  2014-06-23 15:10 [Bug c++/61587] New: Line number of code that triggers "use of deleted function" error is absent from error message Marc.van-Leeuwen at math dot univ-poitiers.fr
                   ` (2 preceding siblings ...)
  2014-06-24  8:21 ` redi at gcc dot gnu.org
@ 2021-12-02 23:47 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-02 23:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|2014-06-24 00:00:00         |2021-12-2

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

end of thread, other threads:[~2021-12-02 23:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-23 15:10 [Bug c++/61587] New: Line number of code that triggers "use of deleted function" error is absent from error message Marc.van-Leeuwen at math dot univ-poitiers.fr
2014-06-23 17:08 ` [Bug c++/61587] " redi at gcc dot gnu.org
2014-06-24  3:40 ` Marc.van-Leeuwen at math dot univ-poitiers.fr
2014-06-24  8:21 ` redi at gcc dot gnu.org
2021-12-02 23:47 ` 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).