Boost logo

Boost Users :

Subject: [Boost-users] [boost-users] VC2005 - strange bug (when specializing base template)
From: Igor R (boost.lists_at_[hidden])
Date: 2008-11-13 08:04:58


Hello,

This is not a boost-related issue (except the fact that enable_if is
used), but it might be of interest to the boost-users community.
The following bug was detected in some compicated environment, but the
following seems to be the minimal construct where it appears (compile
in Debug mode; see comments in Test::func() ).

// main.cpp
#include <boost/type_traits/is_integral.hpp>
#include <boost/utility.hpp>

class BasicVersion
{};

template<typename Param, class Enable = void> class Version1 : public
BasicVersion
{
protected:
  Version1() : verData_(2)
  {}
  void go()
  {
    verData_ = 3;
  }
  int verData_;
};

template<typename Param, class Enable = void> class TestBase
{};
template<typename Param> class TestBase<Param, typename
boost::enable_if<boost::is_integral<Param> >::type> : public
Version1<Param>
{};

template<class Param> class Test : private boost::noncopyable, public
TestBase<Param>
{
public:
  void func()
  {
    go(); // This works well
    TestBase::go(); // This jumps to an incorrect place (bad "this"),
verData_ contains garbage

    /*
    the following code is generated for the previous 2 calls:
                go();
004116D3 mov ecx,dword ptr [this]
004116D6 add ecx,4
004116D9 call Version1<int,void>::go (4110F5h)
                TestBase::go();
004116DE mov ecx,dword ptr [this]
004116E1 add ecx,8
004116E4 call Version1<int,void>::go (4110F5h)

   */
  }
private:
  int data_;
};

int main()
{
  Test<int> test;
  test.func();
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net