Home Dashboard Directory Help

pointer traits do not work for shared pointers to abstract classes by Stefan137



Sign in
to vote
Type: Bug
ID: 781594
Opened: 3/18/2013 10:41:56 AM
Access Restriction: Public
User(s) can reproduce this bug


std::pointer_traits cannot be applied to shared_ptr (or other smart pointer types) pointing to abstract classes. Also consult this forum question: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/9be8b79d-c14c-4baa-bae5-d3b9dbabc5e7.
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:29 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 5/6/2013 at 1:57 PM
Hi again,

We've fixed this bug, and the fix will be available in VC12.

Reminder: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 3/26/2013 at 12:35 AM

Thanks for reporting this bug. I wanted to let you know what's happening with it. I'm still keeping track of it, but it's been resolved as "Deferred" because we may not have time to fix it in VC12. (Note: VC8 = VS 2005, VC9 = VS 2008, VC10 = VS 2010, VC11 = VS 2012.)

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 3/19/2013 at 12:31 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/18/2013 at 11:52 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Stefan137 on 3/19/2013 at 2:20 AM
For the time being, a partial specialization like the following might help. (Note that a standard-conforming implementation would, for example, also work for user-defined pointer types having more than one template argument.)

#include <memory>
#include <type_traits>

namespace helper{
    // Inspired by Herb Sutter's "More Exceptional C++".
    class no{};
    class yes{no no_[2];};
    // Determine element_type according to
    template<class PT>
    static yes has_element_type(const typename PT::element_type*);
    template<class PT>
    static no has_element_type(...);
    template<class PT, int = sizeof(has_element_type<PT>(0))>
    struct element{
        typedef typename PT::element_type type;

    template<template<class> class P, class T>
    struct element<P<T>, sizeof(no)>{
        typedef T type;
    // Determine difference_type according to
    template<class PT>
    static yes has_difference_type(const typename PT::difference_type*);
    template<class PT>
    static no has_difference_type(...);
    template<class PT, int = sizeof(has_difference_type<PT>(0))>
    struct difference{
        typedef typename PT::difference_type type;

    template<class PT>
    struct difference<PT, sizeof(no)>{
        typedef std::ptrdiff_t type;
    // Determine rebind type similar to;
    // template using declaration not yet supported.
    template<class PT, class U>
    static yes has_rebind(const typename PT::template rebind<U>*);
    template <class PT, class U>
    static no has_rebind(...);
    template<class PT, class U, int = sizeof(has_rebind<PT, U>(0))>
    struct rebind{
        typedef typename PT::template rebind<U>::other type;

    template<template<class> class P, class T, class U>
    struct rebind<P<T>, U, sizeof(no)>{
        typedef P<U> type;
    // Check whether T is a (possibly cv-qualified) void type; cf.
    template<class T, bool = std::is_void<T>::value>
    struct pointer_to{
        typedef int type;
    template<class T>
    struct pointer_to<T, false>{
        typedef T& type;

namespace std{
    template<template<class> class P,class T>
    struct pointer_traits<P<T> >{
        typedef P<T> pointer;
        typedef typename helper::element<P<T>>::type element_type;
        typedef typename helper::difference<P<T>>::type difference_type;
        static pointer pointer_to(typename helper::pointer_to<T>::type x){
            return P<T>::pointer_to(x);
        template<class U>
        struct rebind{
            typedef typename helper::rebind<P<T>, U>::type other;
File Name Submitted By Submitted On File Size  
WorkAround.cpp 3/19/2013 3 KB