public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Template instantiation & inheritance - fixed, but can I scrap the   warning I get to do it?
@ 2010-02-27 22:43 John Graham
       [not found] ` <5b7094581002270824v669fa771y3d5f017c0aefa11c@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: John Graham @ 2010-02-27 22:43 UTC (permalink / raw)
  To: gcc-help

Okay, I seem to have gone and answered my own question!

For some reason I couldn't do:


template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;


Because I'd get a few of the following back:


ccrtp/rtp.h: In member function 'ost::IPV4Host
ost::TRTPSessionBase<RTPDataChannel, RTCPChannel,
ServiceQueue>::getDataSender(ost::tpport_t*) const [with
RTPDataChannel = ost::RTPBaseUDPIPv4Socket, RTCPChannel =
ost::RTPBaseUDPIPv4Socket, ServiceQueue = ost::AVPQueue]':
rtpaudioport.cpp:24:   instantiated from here
ccrtp/rtp.h:205: error: no matching function for call to
'ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t*&)'
ccrtp/channel.h:114: note: candidates are: ost::IPV4Host
ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t&) const


But I can do:


inline template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;


And that seems to generate the necessary class information.

Still seems like a bit of a mystery that this has to be specifically
generated though... is there a reason for that?

Also, I have to turn off -pedantic-errors to compile that, as it's a
non-standard extension. Is there any way I can specify an
-fno-<something> option to turn this error off:

error: ISO C++ forbids the use of 'inline' on explicit instantiations


Thanks again,

John G

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Template instantiation & inheritance - fixed, but can I scrap the   warning I get to do it?
       [not found] ` <5b7094581002270824v669fa771y3d5f017c0aefa11c@mail.gmail.com>
@ 2010-02-28  2:28   ` John Graham
  2010-03-01 17:44     ` Brian Budge
  0 siblings, 1 reply; 6+ messages in thread
From: John Graham @ 2010-02-28  2:28 UTC (permalink / raw)
  To: Brian Budge; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2618 bytes --]

> Can you post a minimal example?

An example of which bit? The only one I've made up so far is attached.
It shows a basic configuration that compiles when the template
instantiations are in a header file that's included in several
translation units - set CFLAGS to define SUPER and/or SUB to include a
particular template instantiation.

However, the example attached doesn't *quite* show what I had in
practice - the only difference is that when I instantiate the
templates in a header file in my real library, I don't have to do
anything for the superclass - that all just seems to get generated.
However, in the example attached, you don't get the superclass's
template information unless you instantiate it separately.

John G


On Sat, Feb 27, 2010 at 4:24 PM, Brian Budge <brian.budge@gmail.com> wrote:
> Hi John -
>
> I was surprised to see that compile :).  You should be placing explicit
> instantiations in a source file.  I'm not sure why it didn't work before.
> Can you post a minimal example?
>
> On Feb 27, 2010 5:19 AM, "John Graham" <johngavingraham@googlemail.com>
> wrote:
>
> Okay, I seem to have gone and answered my own question!
>
> For some reason I couldn't do:
>
>
> template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
> ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;
>
>
> Because I'd get a few of the following back:
>
>
> ccrtp/rtp.h: In member function 'ost::IPV4Host
> ost::TRTPSessionBase<RTPDataChannel, RTCPChannel,
> ServiceQueue>::getDataSender(ost::tpport_t*) const [with
> RTPDataChannel = ost::RTPBaseUDPIPv4Socket, RTCPChannel =
> ost::RTPBaseUDPIPv4Socket, ServiceQueue = ost::AVPQueue]':
> rtpaudioport.cpp:24:   instantiated from here
> ccrtp/rtp.h:205: error: no matching function for call to
> 'ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t*&)'
> ccrtp/channel.h:114: note: candidates are: ost::IPV4Host
> ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t&) const
>
>
> But I can do:
>
>
> inline template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
> ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;
>
>
> And that seems to generate the necessary class information.
>
> Still seems like a bit of a mystery that this has to be specifically
> generated though... is there a reason for that?
>
> Also, I have to turn off -pedantic-errors to compile that, as it's a
> non-standard extension. Is there any way I can specify an
> -fno-<something> option to turn this error off:
>
> error: ISO C++ forbids the use of 'inline' on explicit instantiations
>
>
> Thanks again,
>
> John G
>

[-- Attachment #2: temp-inst.tar.bz2 --]
[-- Type: application/x-bzip2, Size: 6575 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Template instantiation & inheritance - fixed, but can I scrap the   warning I get to do it?
  2010-02-28  2:28   ` John Graham
@ 2010-03-01 17:44     ` Brian Budge
  2010-03-06 12:00       ` John Graham
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Budge @ 2010-03-01 17:44 UTC (permalink / raw)
  To: John Graham; +Cc: gcc-help

Hi John -

I'm not 100% clear in regard to how this should behave according to
the standard (or even if the standard has anything to do with this gcc
flag), I believe that since you are forcing explicit instantiation,
you will probably have to instantiate ALL used templates, even if they
are templates used by an instantiated template.   Maybe someone in the
know could confirm?

Perhaps you aren't using the same flag in the compilation of your
program, and the code can see the template directly?  Then you would
have the explicitly instantiated subclass, and because you aren't
telling the compiler to explicitly instantiate while compiling the
executable, it takes care of implicitly instantiating anything used by
the subclass?  This is just a guess.  Do you use that flag for
compilation of all units?

  Brian

On Sat, Feb 27, 2010 at 10:37 AM, John Graham
<johngavingraham@googlemail.com> wrote:
>> Can you post a minimal example?
>
> An example of which bit? The only one I've made up so far is attached.
> It shows a basic configuration that compiles when the template
> instantiations are in a header file that's included in several
> translation units - set CFLAGS to define SUPER and/or SUB to include a
> particular template instantiation.
>
> However, the example attached doesn't *quite* show what I had in
> practice - the only difference is that when I instantiate the
> templates in a header file in my real library, I don't have to do
> anything for the superclass - that all just seems to get generated.
> However, in the example attached, you don't get the superclass's
> template information unless you instantiate it separately.
>
> John G
>
>
> On Sat, Feb 27, 2010 at 4:24 PM, Brian Budge <brian.budge@gmail.com> wrote:
>> Hi John -
>>
>> I was surprised to see that compile :).  You should be placing explicit
>> instantiations in a source file.  I'm not sure why it didn't work before.
>> Can you post a minimal example?
>>
>> On Feb 27, 2010 5:19 AM, "John Graham" <johngavingraham@googlemail.com>
>> wrote:
>>
>> Okay, I seem to have gone and answered my own question!
>>
>> For some reason I couldn't do:
>>
>>
>> template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
>> ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;
>>
>>
>> Because I'd get a few of the following back:
>>
>>
>> ccrtp/rtp.h: In member function 'ost::IPV4Host
>> ost::TRTPSessionBase<RTPDataChannel, RTCPChannel,
>> ServiceQueue>::getDataSender(ost::tpport_t*) const [with
>> RTPDataChannel = ost::RTPBaseUDPIPv4Socket, RTCPChannel =
>> ost::RTPBaseUDPIPv4Socket, ServiceQueue = ost::AVPQueue]':
>> rtpaudioport.cpp:24:   instantiated from here
>> ccrtp/rtp.h:205: error: no matching function for call to
>> 'ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t*&)'
>> ccrtp/channel.h:114: note: candidates are: ost::IPV4Host
>> ost::RTPBaseUDPIPv4Socket::getSender(ost::tpport_t&) const
>>
>>
>> But I can do:
>>
>>
>> inline template class ost::TRTPSessionBase<ost::RTPBaseUDPIPv4Socket,
>> ost::RTPBaseUDPIPv4Socket, ost::AVPQueue>;
>>
>>
>> And that seems to generate the necessary class information.
>>
>> Still seems like a bit of a mystery that this has to be specifically
>> generated though... is there a reason for that?
>>
>> Also, I have to turn off -pedantic-errors to compile that, as it's a
>> non-standard extension. Is there any way I can specify an
>> -fno-<something> option to turn this error off:
>>
>> error: ISO C++ forbids the use of 'inline' on explicit instantiations
>>
>>
>> Thanks again,
>>
>> John G
>>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Template instantiation & inheritance - fixed, but can I scrap the   warning I get to do it?
  2010-03-01 17:44     ` Brian Budge
@ 2010-03-06 12:00       ` John Graham
  2010-03-06 17:14         ` Brian Budge
  0 siblings, 1 reply; 6+ messages in thread
From: John Graham @ 2010-03-06 12:00 UTC (permalink / raw)
  To: Brian Budge; +Cc: gcc-help

> I believe that since you are forcing explicit instantiation,
> you will probably have to instantiate ALL used templates, even if they
> are templates used by an instantiated template.   Maybe someone in the
> know could confirm?

Fair enough - no mean feat since the compiler nicely tells you what
it's missing, I guess. It's just a puzzle to me that I didn't seem to
have to do any extra "instantiating" in my library but I do in a test
case - I'm obviously missing something subtle in the library.


> Perhaps you aren't using the same flag in the compilation of your
> program, and the code can see the template directly?  Then you would
> have the explicitly instantiated subclass, and because you aren't
> telling the compiler to explicitly instantiate while compiling the
> executable, it takes care of implicitly instantiating anything used by
> the subclass?  This is just a guess.  Do you use that flag for
> compilation of all units?

In the example I sent earlier (as in the "real" case) I use
-fno-implicit-templates for the library, but *not* for the program.
And the program can definitely see all the template definitions as
they're included in header files, so I don't think that'll be the
case...

John G

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Template instantiation & inheritance - fixed, but can I scrap the   warning I get to do it?
  2010-03-06 12:00       ` John Graham
@ 2010-03-06 17:14         ` Brian Budge
  2010-03-06 21:16           ` John Graham
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Budge @ 2010-03-06 17:14 UTC (permalink / raw)
  To: John Graham; +Cc: gcc-help

I think we're saying the same thing :)  It will work for the program
when it can see the headers, and implicit instantiation is allowed.

On Sat, Mar 6, 2010 at 4:00 AM, John Graham
<johngavingraham@googlemail.com> wrote:
>> I believe that since you are forcing explicit instantiation,
>> you will probably have to instantiate ALL used templates, even if they
>> are templates used by an instantiated template.   Maybe someone in the
>> know could confirm?
>
> Fair enough - no mean feat since the compiler nicely tells you what
> it's missing, I guess. It's just a puzzle to me that I didn't seem to
> have to do any extra "instantiating" in my library but I do in a test
> case - I'm obviously missing something subtle in the library.
>
>
>> Perhaps you aren't using the same flag in the compilation of your
>> program, and the code can see the template directly?  Then you would
>> have the explicitly instantiated subclass, and because you aren't
>> telling the compiler to explicitly instantiate while compiling the
>> executable, it takes care of implicitly instantiating anything used by
>> the subclass?  This is just a guess.  Do you use that flag for
>> compilation of all units?
>
> In the example I sent earlier (as in the "real" case) I use
> -fno-implicit-templates for the library, but *not* for the program.
> And the program can definitely see all the template definitions as
> they're included in header files, so I don't think that'll be the
> case...
>
> John G
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Template instantiation & inheritance - fixed, but can I scrap the   warning I get to do it?
  2010-03-06 17:14         ` Brian Budge
@ 2010-03-06 21:16           ` John Graham
  0 siblings, 0 replies; 6+ messages in thread
From: John Graham @ 2010-03-06 21:16 UTC (permalink / raw)
  To: Brian Budge; +Cc: gcc-help

> I think we're saying the same thing :)  It will work for the program
> when it can see the headers, and implicit instantiation is allowed.

No, that's what's puzzling to me - when I compile the program,
implicit instantiation is allowed, and it can see the headers, but it
complains that it can't find the templates.

Like I said, not a major problem (now I know what to do :p), just puzzling.

John G

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-03-06 21:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-27 22:43 Template instantiation & inheritance - fixed, but can I scrap the warning I get to do it? John Graham
     [not found] ` <5b7094581002270824v669fa771y3d5f017c0aefa11c@mail.gmail.com>
2010-02-28  2:28   ` John Graham
2010-03-01 17:44     ` Brian Budge
2010-03-06 12:00       ` John Graham
2010-03-06 17:14         ` Brian Budge
2010-03-06 21:16           ` John Graham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).