Opened 10 years ago

Closed 10 years ago

#8152 closed Bugs (invalid)

operator_bool write access violation error in MSVC builds

Reported by: rossmpublic@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc: Peter Dimov

Description

Using the unspecified_bool_type operator and the following pragma is causing write access violations with the Microsoft compiler:

#pragma pointers_to_members(full_generality, virtual_inheritance)

This behavior has been confirmed for boost_1_44_0 using an msvc90 build and for boost_1_53_0 using a msvc10 build.

Here is the code that reproduces the error:

//------- main.cpp ---------

#pragma pointers_to_members(full_generality, virtual_inheritance)

#include "TestClass.h"

int main(int argc, char* argv[])
{
  IntPointer p(new int);
  bool isValid = p;

  TestClass test;
  test.setInt(p);

  return 0;
}

//------ TestClass.h ----------

#pragma once 

#include <boost/shared_ptr.hpp>

typedef boost::shared_ptr<int> IntPointer;

class TestClass
{
public:
  void setInt(IntPointer p);
private:
  IntPointer m_p;
};


//----- TestClass.cpp

#include "TestClass.h"

void TestClass::setInt(IntPointer p)
{
  m_p = p;
  bool isValid = p;
}

Change History (3)

comment:1 by Ross MacGregor <rossmpublic.gmail.com>, 10 years ago

I filed a bug with Microsoft as this does not seem to be directly related to the boost library. You can find a Zip attachment there with my crash test solution in for Visual Studio 2008.

https://connect.microsoft.com/VisualStudio/feedback/details/779972/c-pointers-to-members-pragma-generating-write-access-vilolation#tabs

comment:2 by Ross MacGregor <rossmpublic.gmail.com>, 10 years ago

This is not a bug but an improper use of the pointer_to_members pragma. Info from the MS ticket:

"Your code violates one definition rule in C++ standard. The pragma is used in main.cpp but not in TestClass.cpp. This leads to two inconsistent definitions of the same 'IntPointer'. The code can run correctly if you move the pragma after #include directive because this eliminates the one definition rule violation."

This issue may be closed.

comment:3 by Peter Dimov, 10 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.