This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PCH, and more generally C++ parser performance
>>>>> "Zack" == Zack Weinberg <zack@wolery.cumb.org> writes:
Zack> 1 ... Unless a member of a class template or a member
Zack> template has been explicitly instantiated or explicitly
Zack> specialized, the specialization of the member is implicitly
Zack> instantiated when the specialization is referenced in a
Zack> context that requires the member definition to exist; in
Zack> particular, the initialization (and any associated
Zack> side-effects) of a static data member does not occur unless
Zack> the static data member is itself used in a way that requires
Zack> the definition of the static data member to exist.
Yes, that's the question all right. There are lots of tricky bits in
the standard about the "point of instantiation". It can matter
exactly *where* a template is instantiated. So, if, for example, some
template was unequivocally needed somewhere else, we might have to
then go back and pretend it was actually instantiated inside the
inline function.
There are other questions as well:
inline void f () { class C { friend void g() {}; }; }
void g() {}
I believe this is illegal due to duplicate definitions of `g'. But
you can't know that without parsing `f'.
I understand your basic idea: that the body of a function shouldn't
matter if the function isn't "needed". But, unfortunately (from a
language cleanliness point of view), some information can escape.
After all `static' functions aren't needed either, if they're never
called. The same kind of logic would imply that given:
static void f () { S<int>::i = 3; }
maybe we shouldn't instantiate S<int>::i. But that would sure confuse
a lot of people.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com