|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-06-13 12:24:41
Ion Gaztañaga wrote:
[...]
> template<class Pointer>
> class container
> {
> Pointer ptr;
> public:
> void func()
> { static_pointer_cast<int>(Pointer()); }
> };
>
> } //namespace dummy {
> } //namespace boost {
[...]
> This code compiles in VC 7.1 and VC 8 but fails with gcc, complaining
> the "there is no declaration for static_pointer_cast". If we change
> the header order to:
>
> #include "smart_ptr.h"
> #include "container.h"
> #include "container_factory.h"
>
> This compiles fine because the static_pointer_cast definition is found
> before the call. My first question is:
>
> * Is this gcc error correct? Revising a bit ADL + template issues (a
> fairly complicated logic that should be removed from C++, in my
> opinion) I think that gcc is right.
Questionable. The problem is that for static_pointer_cast<int> to be valid,
static_pointer_cast must be known to be a template. It is understandable why
g++ rejects it without a declaration, but I'm not sure whether this is
conforming now, much less whether it'd be conforming tomorrow if there are
open core issues for this case.
Even if static_pointer_cast<int> is parsed correctly, I recall a core issue
about whether the call should be subject to ADL.
> * If gcc is correct, what is the implementor supposed to do? Every
> templatized class header shouldn't include smart_ptr.h because
> smart_ptr is unknown and it can even be a user-defined class.
To make the above work for raw pointers (these don't have an associated
namespace), the implementor would need to #include boost/pointer_cast.hpp
and add an using declaration for boost::static_pointer_cast. This may or may
not make g++ happy.
> I must have missed something, because otherwise, I would find ADL
> really useless as a robust customization point.
The typical ADL expression doesn't have an explicit <int> template
parameter.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk