https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109551
Bug ID: 109551 Summary: Show location where implicit instantiation first required Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- Copied from https://github.com/llvm/llvm-project/issues/20129 template <class T> struct S1 {}; template <class T> struct S2: S1<T> {}; S2<int> s; template <> struct S1<int> {}; We correctly reject this code: src.cc:4:20: error: specialization of 'S1<int>' after instantiation 4 | template <> struct S1<int> {}; | ^~~~~~~ src.cc:4:20: error: redefinition of 'struct S1<int>' src.cc:1:27: note: previous definition of 'struct S1<int>' 1 | template <class T> struct S1 {}; | ^~ But it would be nice if we also pointed to the location that required the implicit instantiation, i.e. line 3: src.cc:3:9: note: implicit instantiation first required here: 3 | S2<int> s; | ^ EDG does indicate where the implicit instantiation is, although it points to the use of S1<T> as a base class of S2<int> on line 2 (maybe that's better?) "src.cc", line 4: error: explicit specialization of class "S1<int>" must precede its first use (at line 2) template <> struct S1<int> {}; ^ 1 error detected in the compilation of "src.cc".