Bug 58589 - diagnostics: missing proper file:line on C++ compilation error
Summary: diagnostics: missing proper file:line on C++ compilation error
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2013-10-01 11:38 UTC by Jan Kratochvil
Modified: 2021-03-31 20:48 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-09-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2013-10-01 11:38:10 UTC
#include <unordered_map>
#include <memory>
class X {
public:
  int a,&b; /* the reference disables default copy constructor */
  X():b(a) {}
};
class Y {
public:
  std::unordered_map<int,std::unique_ptr<X>> x; /* this hides the error line */
} a,b;
int main() { a=b; }

$ g++ -o test6 test6.C -Wall -std=gnu++11 2>&1|grep test6

Actual:
                 from test6.C:1:
                 from test6.C:1:
                 from test6.C:2:
Expected:
                 from test6.C:5:
(or at ltest test6.C:3)

There are many error lines also mentioning 'X' (although neither 'a' or 'b') but none of them gives any line number where the problem comes from in test6.C.
Editors/IDE (error line parsers) then cannot show where the error comes from.

Also none of the errors is the one making the cause clear which one gets by using plain 'X x;' (instead of using 'X' in unordered_map):
test6.C:3:7: error: non-static reference member ‘int& X::b’, can’t use default assignment operator

BTW clang has the same diagnostics problem.
Comment 1 Manuel López-Ibáñez 2014-06-25 18:43:57 UTC
A minimized testcase would be appreciated: https://gcc.gnu.org/bugs/minimize.html
Comment 2 Manuel López-Ibáñez 2014-08-20 23:37:32 UTC
Waiting for a minimized testcase.
Comment 3 Eric Gallager 2017-09-28 18:52:02 UTC
(In reply to Manuel López-Ibáñez from comment #2)
> Waiting for a minimized testcase.

Changing status to actually be WAITING then.
Comment 4 Jonathan Wakely 2017-09-28 19:03:03 UTC
(In reply to Jan Kratochvil from comment #0)
> #include <unordered_map>
> #include <memory>
> class X {
> public:
>   int a,&b; /* the reference disables default copy constructor */

What has the copy constructor got to do with anything?

std::unique_ptr<X> never tries to copy an X

Reduced:

template<class T>
struct impl
{
  T t;

  impl& operator=(const impl& i) { t = i.t; return *this; }
};

template<class T>
struct unordered_map
{
  impl<T> m_impl;
};

struct unique_ptr {
  unique_ptr& operator=(const unique_ptr&) = delete;
};

struct Y {
  unordered_map<unique_ptr> x;
};

int main() {
  Y a;
  a = a;
}

j.cc: In instantiation of ‘impl<T>& impl<T>::operator=(const impl<T>&) [with T = unique_ptr]’:
j.cc:10:8:   required from here
j.cc:6:38: error: use of deleted function ‘unique_ptr& unique_ptr::operator=(const unique_ptr&)’
   impl& operator=(const impl& i) { t = i.t; return *this; }
                                    ~~^~~~~
j.cc:16:15: note: declared here
   unique_ptr& operator=(const unique_ptr&) = delete;
               ^~~~~~~~

There's nothing showing the location of the "a = a" expression that requires the deleted Y::operator=(const Y&).
Comment 5 Manuel López-Ibáñez 2017-09-28 21:17:25 UTC
(In reply to Jonathan Wakely from comment #4)
> There's nothing showing the location of the "a = a" expression that requires
> the deleted Y::operator=(const Y&).

IMHO, the problem is the instantiation trace:

> j.cc:10:8:   required from here

does not show any useful location. It should show the location of "a = a"