Thread View: comp.std.c++
2 messages
2 total messages
Started by Herb Sutter
Sat, 07 Oct 1995 14:42
Re: Templates and Undefined Functions.
Author: Herb Sutter
Date: Sat, 07 Oct 1995 14:42
Date: Sat, 07 Oct 1995 14:42
34 lines
2381 bytes
2381 bytes
In article <30753E6F@Toronto.LinkAge.com>, Harvey Rook <harveyr@LinkAge.com> wrote: >What does the standard say about templates and inline functions that are >never used? Do they have to contain completly valid code? Or can they be >ignored? Which compiler is right? Template code that is never called should not be generated -- whether inline or out-of-line. Not only does this mean that classes like the one you showed (one which is never instantiated) should never get code generated, but even classes which are instantiated should only have those templated members instantiated that are actually used. In other words, you can have a class with some function that contains illegal code (either always illegal, or illegal to instantiate for a particular type), and the compiler should not generate the code if it is not called. Incidentally, this feature is quite useful... not just because is saves dead code, but because it gives you some flexibility with a template's type restraints if you don't plan to use all features of the template. As you've noticed, though, compilers are always playing catchup with the draft and not all have even basic templates solidly implemented yet. For example, I would be surprised if Visual C++ supported the above requirement (from all that I've heard their template code is still weak... won't run a complete STL implementation, for example). Herb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Herb Sutter 2228 Urwin, Ste 102 voice (416) 618-0184 Connected Object Solutions Oakville ON Canada L6L 2T2 fax (905) 847-6019 [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Templates and Undefined Functions.
Author: David Vandevoorde
Date: Mon, 09 Oct 1995 06:24
Date: Mon, 09 Oct 1995 06:24
54 lines
2818 bytes
2818 bytes
>>>>> "HS" == Herb Sutter <herbs@interlog.com> writes: HS> In article <30753E6F@Toronto.LinkAge.com>, Harvey Rook HS> <harveyr@LinkAge.com> wrote: >> What does the standard say about templates and inline functions >> that are never used? Do they have to contain completly valid code? >> Or can they be ignored? Which compiler is right? HS> Template code that is never called should not be generated -- HS> whether inline or out-of-line. Not only does this mean that HS> classes like the one you showed (one which is never instantiated) HS> should never get code generated, but even classes which are HS> instantiated should only have those templated members instantiated Non-virtual members, that is. Virtual members may be emitted even though they're never called (because it's so hard to predict whether they're actually called or not). HS> that are actually used. In other words, you can have a class with HS> some function that contains illegal code (either always illegal, HS> or illegal to instantiate for a particular type), and the compiler Actually, the code must be ``grammatically correct''; i.e., you you do not have to guarantee things like accessibility, but you must provide correct syntax. HS> should not generate the code if it is not called. Incidentally, HS> this feature is quite useful... not just because is saves dead HS> code, but because it gives you some flexibility with a template's HS> type restraints if you don't plan to use all features of the HS> template. Very true! HS> As you've noticed, though, compilers are always playing catchup HS> with the draft and not all have even basic templates solidly HS> implemented yet. For example, I would be surprised if Visual C++ HS> supported the above requirement (from all that I've heard their HS> template code is still weak... won't run a complete STL HS> implementation, for example). Yes, many compilers --- even some that are good enough to handle HP's STL --- still attempt to instantiate inline-members of template classes whether used ot not. And a pain it is... (Check my valarray-source for sample-contortions :) Daveed --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads