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
On Fri, Aug 25, 2000 at 12:19:30AM -0700, Mark Mitchell wrote:
> >>>>> "Zack" == Zack Weinberg <zack@wolery.cumb.org> writes:
> Zack> [Perhaps the standard has weasel words permitting us not
> Zack> to call f]
>
> I don't think there are any such weasel words -- but I could be
> wrong.
Hmm. I read bits of the standard and I can make a case for us being
required *not* to call f. Look at 14.7.1, paragraphs 1, 7, 9:
1 ... Unless a member of a class template or a member template
has been explicitly instantiated or explicitly specialized, the
specialization of the member is implicitly instantiated when
the specialization is referenced in a context that requires
the member definition to exist; in particular, the
initialization (and any associated side-effects) of a static
data member does not occur unless the static data member is
itself used in a way that requires the definition of the
static data member to exist.
7 The implicit instantiation of a class template does not cause
any static data members of that class to be implicitly
instantiated.
9 An implementation shall not instantiate a function template, a
member template, a member class, or a static data member of a
class template that does not require instantiation.
I'm reading that to say that S<int>::i shall be instantiated if and
only if it is "required to exist." The question is then whether its
sole use inside an inline function which is not itself used, g,
requires it to exist. I can't find anything in the standard about
inlines that are defined and not used in a translation unit. I'd
argue that the as-if rule means it is not required (and is therefore
forbidden, per 14.7.1p9) because the program cannot tell whether
S<int>::i exists.
> Zack> Even if there are no such weasel words, couldn't we arrange
> Zack> to call f and throw the value away?
>
> Yes, we could call `f' and throw the value away -- but how would we
> know to do that without parsing `g'?
I imagined calling f once as soon as we saw
template <class T> int S<T>::i = f();
and using its value for the first instantiation of S<T> we encounter.
But that's not right, because we might never instantiate S<T>.
zw