#256 Avoid instantiating the pointed-to type in _StorageType

open-later
2
2012-03-05
2012-03-05
Anonymous
No

Consider the current code for _StorageType<_Tp*> specialization (in stlport/stl/pointers/_tools.h):

template <class _Tp>
struct _StorageType<_Tp*> {
// Even if we detect a pointer type we use dispatch function to consider if it can be stored as a void*.
// For instance function pointer might not necessarily be convertible to void*.
enum { use_void_ptr = (sizeof(_UseVoidPtrStorageType(__true_type(),
__STATIC_CAST(_Tp*, 0))) == sizeof(char*)) };
enum { use_const_volatile_void_ptr = use_void_ptr };
typedef typename __select<use_void_ptr,
void*,
_Tp*>::_Ret _QualifiedType;

If _Tp is a template, this STATIC_CAST will instantiate it. This is (a) unneeded, and (b) can result in a compilation error if instantiation of _Tp will, in turn, reference _StorageType<_Tp*>::_QualifiedType, which is not defined at this point.

Instantiation happens because of the argument dependent lookup of a friend _UseVoidPtrStorageType() in _Tp. This is definitely not an intended behavior. The fix is to refer to _UseVoidPtrStorageType() and similar functions by their fully-qualified names. The patch is attached.

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-03-05

    Fix.

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-03-05

    A minimized case of compilation failure

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-03-05

    Note that you can not reproduce this bug with gcc - it will silently ignore the instatiation failure. It is reproducible with Clang and Comeau.

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2012-03-05

    Looks like ADL (aka Koenig lookup) bug of mentioned compilers.

    Report is incomplete: no reference to STLport's code, no reference to compilers, no reference to OS. Absent message from compiler (item one: what happens?).

     
  • Petr Ovtchenkov

    Petr Ovtchenkov - 2012-03-05
    • priority: 5 --> 2
    • assigned_to: nobody --> complement
    • status: open --> open-later
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks