Boost logo

Boost :

From: Martin Bonner (Martin.Bonner_at_[hidden])
Date: 2007-07-06 04:00:16


----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Dean Michael Berris
Sent: 06 July 2007 08:00 To: boost_at_[hidden]
Subject: [boost] extern placeholders and MSVC 8

> 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
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_at_[hidden]
www.pi-shurlok.com
disclaimer

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk