This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: (nessun oggetto)
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Graziano Servizi <Graziano dot Servizi at bo dot infn dot it>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 10 Oct 2014 15:21:26 +0100
- Subject: Re: (nessun oggetto)
- Authentication-results: sourceware.org; auth=none
- References: <5437E6CD dot 9050206 at bo dot infn dot it>
This is not the right list to ask questions about the standard, this
list is for help using GCC.
On 10 October 2014 15:01, Graziano Servizi <Graziano.Servizi@bo.infn.it> wrote:
> I'm wondering in reading the 14.7.1.4 example of the standard, about
> template implicit instantiation: there it is found the following code
>
> template<class T> struct Z {
> void f();
> void g();
> };
> void h() {
> Z<int> a; // instantiation of class Z<int> required
> Z<char>* p; // instantiation of class Z<char> not required
> Z<double>* q; // instantiation of class Z<double> not required
> a.f(); // instantiation of Z<int>::f() required
> p->g(); // instantiation of class Z<char> required, and
> // instantiation of Z<char>::g() required
> }
>
> followed by this comment:
>
> "Nothing in this example requires class
>
> Z<double>, Z<int>::g(), or Z<char>::f()
>
> to be implicitly instantiated."
>
>
> Almost all is clear enaugh to me, but my question is: does the line
>
> p->g();
>
> imply allocation of the pointer p to hold an address for the member function
> g ONLY?
>
> I didn't find any new operator before.
>
> And what about this pointer at the end of the expression? Is it implicitly
> released as well as it was "implicitly allocated"?
>
> Or all I wrote up to now is meaningless? ....
Yes, I think it's meaningless. There is no allocation or deallocation
in the example, it is only talking about template instantiation.
If the code was executed the expression p->g() would probably crash
because the pointer is uninitialized.