From 6867213877607416588
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7b79e159eaf7fc79,start
X-Google-Attributes: gidf78e5,public
Path: g2news1.google.com!news1.google.com!news.glorb.com!peer1.news.newnet.co.uk!peer1.news.newnet.co.uk!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: usenet@disemia.com (edA-qa mort-ora-y)
Newsgroups: comp.std.c++
Subject: Template visibility / linkage
Date: Tue, 22 Jun 2004 17:53:30 +0000 (UTC)
Organization: Arcor
Lines: 71
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <40d85d55$0$25274$9b4e6d93@newsread2.arcor-online.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: mail2news.demon.co.uk 1087926810 22987 10.0.0.1 (22 Jun 2004 17:53:30 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 22 Jun 2004 17:53:30 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1BcpSb-0005yb-00
	for mail2news@news.news.demon.net; Tue, 22 Jun 2004 17:53:30 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i5MHrRRR002940; Wed, 23 Jun 2004 03:53:27 +1000 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i5MHrQVB002930;
	Wed, 23 Jun 2004 03:53:26 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-User-Agent: Mozilla Thunderbird 0.6 (X11/20040502)
X-Accept-Language: en-us, en
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 22 Jun 2004 18:24:53 MEST
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Level: 
X-Spam-Status: No, hits=-4.9 required=5.2 tests=BAYES_00 autolearn=ham 
	version=2.60-mulga_r1
Xref: g2news1.google.com comp.std.c++:983

I am having difficulty determining what the proper linkage/locating of 
templates and their specializations (Section 3.5.4 briefly mentions 
template linkage, and 14 talks about the export keyword).

Situation A:

In <header1>:
template<typename T> void func( T val );

In <src1>:
#include "header1"
template<> void func<int>( int val ) { ... }

In <src2>:
#include "header1"
..
int a;
func( a );

Comments: In this situation, should the code in <src2> end up calling 
the template specialization as defined in <src1>, even though it is 
unaware of its existence at compile time?  Since the linkage of the 
template is external, and it has the same signature, I would assume yes.

Situation B:

In <header1>:
template<typename T> void func( T val )
{ /* primary def */ }

In <src1>:
#include "header1"
template<> void func<int>( int val ) ...

In <src2>:
#include "header1"
..
int a;
func( a );

Comments: Should the code in <src2> use the primary template definition 
or should it use the specialization from <src1>?  My reading of the 
standard indicates it should use the specializaed form, since the 
template matching doesn't appear to be limited to the current 
translation unit, and the the function signature will match that in 
<src1> at link time.

I am unclear of whether the template matching rules hold over to link 
time, or only for the current translation unit.  That is, if <src2>, in 
both cases, were to also include <src1> it would be clear that it usese 
the specialization, but since it doesn't include <src1>, the compilation 
finishes without knowledge of the specialization.  Does the linker then 
/do the right thing/?

And I'm completely unclear on classes, whether they should match 
identical declarations in other units, as there would be signifcant 
sizing problems for the compiler.  Though I can't see why it would be 
disallowed according to the standard.

-- 
edA-qa mort-ora-y (Producer)
Trostlos Records <http://trostlos.org/>

"What suffering would man know if not for his own?"

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



