pointer_traits on custom void pointers - by Arno_S

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 764717 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/26/2012 6:49:22 AM
Access Restriction Public


#include "stdafx.h"
#include <memory>

template< class T >
class pointerwrapper {
	T* m_pt;
	pointerwrapper(T* pt): m_pt(pt) {}
	typedef T* pointer;
	typedef T element_type;
	pointerwrapper pointer_to(T& t) {
		return pointerwrapper<T>(std::addressof(t));

class pointerwrapper<void> {
	void* m_pt;
	pointerwrapper(void* pt): m_pt(pt) {}
	typedef void* pointer;
	typedef void element_type;

int _tmain(int argc, _TCHAR* argv[])
	std::pointer_traits<pointerwrapper<int>> test;
	std::pointer_traits<pointerwrapper<void>> test2;
	return 0;


1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0(205): error C2182: '_Val' : illegal use of type 'void'
1>          c:\users\schoedl\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(31) : see reference to class template instantiation 'std::pointer_traits<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=pointerwrapper<void>
1>          ]

because it tries to instantiate pointer_to(void&), which from the standard I believe it should not.
Sign in to post a comment.
Posted by Stephan [MSFT] on 11/12/2012 at 6:48 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in the next release of our C++ Standard Library implementation.

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 Helen [MSFT] on 9/26/2012 at 11:23 PM
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 Arno_S on 9/26/2012 at 7:42 AM
The problem can be fixed by modifying the pointer_traits definition in xmemory0 to

        // TEMPLATE CLASS pointer_traits
template<class _Ty, bool>
    struct pointer_traits_base;

template<class _Ty>
    struct pointer_traits_base< _Ty, false >
    static _Ty pointer_to(typename _Get_element_type<_Ty>::type& _Val)
        {    // convert raw reference to pointer
        return (_Ty::pointer_to(_Val));

template<class _Ty>
    struct pointer_traits_base< _Ty, true >
template<class _Ty>
    struct pointer_traits : public pointer_traits_base< _Ty, std::is_void< typename _Get_element_type<_Ty>::type >::value >
    {    // defines traits for arbitrary pointers
    typedef pointer_traits<_Ty> other;

    typedef typename _Get_element_type<_Ty>::type element_type;
    typedef _Ty pointer;
    typedef typename _Get_ptr_difference_type<_Ty>::type difference_type;

    template<class _Other>
        struct rebind
        {    // converts X<element_type> to X<_Other>
        typedef typename _Get_rebind_type<_Ty, _Other>::type other;
Posted by Helen [MSFT] on 9/26/2012 at 6:53 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)