
Hi Everyone,
I've encountered a problem with MSVC which I have no idea how to go around with regards to using extern placeholders for template method type deductions. Let me give an example:
template <class T> struct some_type { };
struct a_type { } ;
extern a_type placeholder ;
template <class T> some_type<T> method(T) { return some_type<T>(); };
// ... { method(placeholder); }
The code works (compiles fine) in GCC -- it doesn't bother looking for the placeholder during link time. However MSVC 8 throws a fit and doesn't want to link the executable because it keeps looking for the implementation of placeholder -- where the code obviously doesn't require linking to it in any way, except for the purposes of type deduction in the template method.
Am I encountering an MSVC bug? I don't think so. The call: method(placeholder); is "potentially evaluated" and hence the name "placeholder" is "used" (see 3.2/2 of the standard) and 3.2/3 says: "Every program shall contain exactly one definition of every non-inline function or object that is used in that
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Dean Michael Berris Sent: 06 July 2007 08:00 To: boost@lists.boost.org Subject: [boost] extern placeholders and MSVC 8 program; no diagnostic required."
Is there a better way of going about this?
I think we need more background. Options: - Define 'placeholder' - Change the declarations to extern a_type* placeholder (and define placeholder to null somewhere). some_type<T> method(T*) { return some_type<T>(); }; - Make 'method' take no arguments and explicit specify the template arguments. - Something else.
Insights would be most appreciated.
Thanks in advance!
-- Martin Bonner Project Leader PI SHURLOK LTD Telephone: +44 1223 441434 / 203894 (direct) Fax: +44 1223 203999 Email: martin.bonner@pi-shurlok.com www.pi-shurlok.com disclaimer