Article View: comp.std.c++
Article #2146Re: Templates and Undefined Functions.
From: 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. ]
Technical Details
Message-ID:
<4563k6$abp@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: herbs@interlog.com (Herb Sutter) Newsgroups: comp.std.c++ Subject: Re: Templates and Undefined Functions. Date: 7 Oct 1995 14:42:14 GMT Organization: Connected Object Solutions (div of Daystar Software Systems Design Inc.) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4563k6$abp@engnews2.Eng.Sun.COM> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text Content-Length: 1648 Originator: clamage@taumet