http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60246
Bug ID: 60246 Summary: Emit debug info for explicit template instantiation definitions Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: dblaikie at gmail dot com CC: echristo at gmail dot com A possible size optimization for debug info exists whenever an explicit template instantiation declaration/definition is present. If, in the translation unit that contains the explicit instantiation definition, the full type is always emitted, then in the instantiation declaration translation units the definition can be omitted in favor of just a declaration. I haven't done the analysis to see how valuable this is, but for simple things like std::string it should fire and save a slew of debug info in consumers. The problem is that this isn't backwards compatible (if the optimization is done on the basis of declarations some debug info from (albeit unnecessary/unuseful) explicit instantiations will be lost). If the explicit instantiation declaration is actually useful (saves on code emission in the declaration translation units and causes code to be emitted in the defining translation unit) then this optimization is safe already - the emission of the code for the member function will cause the type to be emitted there. But in the degenerate case such as: template<typename T> struct foo { // neither of these members would cause code to be emitted int i; void f1(); // void f2() {} // this would though }; // template<typename T> void foo<T>::f1() { } // or this template struct foo<int>; no functions are emitted (so the explicit instantiation decl/def was pointless, but someone might write this) and thus the assumption fails and debug info is broken (no translation unit ends up with the definition of 'foo<int>'). The first step is to ensure that the definition is always emitted in a translation unit with an explicit template instantiation definition. Then at some point in the future its presence can be assumed and explicit instantiation declarations can be optimized more aggressively.