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

            Bug ID: 109382
           Summary: Error inside virtual function of class template does
                    not show point of instantiation
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zeratul976 at hotmail dot com
  Target Milestone: ---

Given the following invalid code:

struct Base {
  virtual void f() = 0;
};
template <typename T>
struct C : Base {
  void f() override {
    T().waldo();
  }
};
int main() {
  C<int> obj;
}

The error is printed as follows:

$ g++-12 -c test.cpp
test.cpp: In instantiation of ‘void C<T>::f() [with T = int]’:
test.cpp:6:8:   required from here
test.cpp:7:9: error: request for member ‘waldo’ in ‘0’, which is of non-class
type ‘int’
    7 |     T().waldo();
      |     ~~~~^~~~~

The error is missing a "required from here" line pointing to `C<int> obj;`.

If you imagine everything above main() being library code, it can be hard for a
user to tell which line of the user's code is triggering the error in the
library.

Reply via email to