473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VC2005 and boost::shared_ptr

Hello group,

There seems to be a bug int the interop layer in VC2005 when dealing
with certain pointer types (or values?)

Here is a repro case using Boost version 1.32 and C++/CLI :

using namespace System;

#pragma unmanaged
#include <boost/shared_ptr.hpp>
boost::shared_ptr<int> ReturnAPointer()
{
return boost::shared_ptr<int>();
}

#pragma managed
int main(array<System::String ^> ^args)
{
boost::shared_ptr<int> ptr=ReturnAPointer();
if (ptr)
{
System::Console::WriteLine("integer : "+ (*ptr));
}
}

ReturnAPointer clearly returns a NULL smart pointer (px==0). The
boolean operator for shared_ptr is :

typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}

Clearly, this operator should return an int** equal to 0, and indeed it
does so in the native layer.

However, back in managed code, the return value of boolean operator -
as shown by Visual 2005 - is 0xffffffff. Therefore, the WriteLine
function is called, which, of course causes an assertion in
shared_ptr::operator*.

The obvious workaround is to replace the test by :
if (ptr.get()!=NULL)
But it kind-of defeats the whole purpose of shared_ptr' boolean
operator, and it may be difficult to find those cases in existing code.

Before I report this to MS feedback, can anyone confirm the behaviour?
Any idea on a solution?

Thanks in advance

Arnaud
MVP - VC

PS : The problem is the same whatever the specialisation of shared_ptr

Apr 7 '06 #1
2 2101
ad******@club-internet.fr wrote:
ReturnAPointer clearly returns a NULL smart pointer (px==0). The
boolean operator for shared_ptr is :

typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}

Clearly, this operator should return an int** equal to 0, and indeed it
does so in the native layer.
Well, it's actually an "int* boost::shared_ptr<int>::*" (e.g. a pointer
to boost::shared_ptr<int> member variable of type int*).
However, back in managed code, the return value of boolean operator -
as shown by Visual 2005 - is 0xffffffff. Therefore, the WriteLine
function is called, which, of course causes an assertion in
shared_ptr::operator*.


This might be a problem with the handling of pointer to members. You
could try fiddling with the pointer-to-member related compiler switches.

Tom
Apr 7 '06 #2
Tom Widmer [VC++ MVP] wrote:
Well, it's actually an "int* boost::shared_ptr<int>::*" (e.g. a
pointer to boost::shared_ptr<int> member variable of type int*).
Yep, you're right. So much for worknig late in the night on that kind of
stuff ;-)
However, back in managed code, the return value of boolean operator -
as shown by Visual 2005 - is 0xffffffff. Therefore, the WriteLine
function is called, which, of course causes an assertion in
shared_ptr::operator*.


This might be a problem with the handling of pointer to members. You
could try fiddling with the pointer-to-member related compiler
switches.


I've tried all the possible combinations of vmm/vms/vmv and vmb/vmg compiler
switches with no luck.

I've opened a bug report here :
http://lab.msdn.microsoft.com/Produc...9-99cabee9df90

Arnaud
MVP - VC
Apr 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ryan Mitchley | last post by:
Hi all Given bool bResult; shared_ptr<cSampleData> pNewData; shared_ptr<cBase> pNewBase; where cSampleData is descended from cBase, the following gives me a valid pNewData to the correct...
2
by: krema2ren | last post by:
Hi I've the following header problem that I need two classes to know each other through a boost::shared_ptr. Does any of you smart guys have a solution? A.h ---------------------- #include...
6
by: Toby Bradshaw | last post by:
Hi, Consider the following: class A { public: virtual bool foo() = 0; };
4
by: EnsGabe | last post by:
Suppose you have a class heirarchy as such: class Base{ .... }; class Mid1 : public Base{ ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.