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

            Bug ID: 92727
           Summary: Idea for better error messages
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at westcontrol dot com
  Target Milestone: ---

Consider this code:

#include <vector>
#include <memory>

class Y {int i;};

class X {
    std::unique_ptr<Y> sp;
    int i;
};

int main() {
    std::vector<X> v;
    X x;
    v.push_back(x);                    // Line A
    // v.push_back(std::move(x));      // Line B
}


It is a simple mistake - class X has a unique_ptr and can't be copied, but the
push_back tries to copy it.

The errors generated, however, contain a lot of unhelpful information about
allocators for the vector.  They hide the useful part of the messages, which
is:

    note: 'X::X(const X&)' is implicitly deleted because the default definition
    would be ill-formed

It is an extra note, rather than the error message, but is key for the user to
identify the problem.

Would it be possible to hide the messages concerning the allocator here?  In
general, would it be possible to hide the messages that deal with template
parameters that are unchanged from the default?  That would let the user see
messages that are relevant to the code /they/ have written, rather than
implementation details in the libraries and headers.

Even better, in this case, would be a hint that the user needs a std::move, as
shown in line B.


(Yes, I know I may be asking for the impossible here, or at least for the very
difficult.  But it is the kind of thing that makes C++ development harder than
it should be.)

Reply via email to