CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2006
    Posts
    151

    move constructor is ignored?

    Hi,

    I've just written my first move constructors and move assignment operators. They seem to compile just fine, but when I try to set a breakpoint inside them, the debugger acts like they don't even exist. It acts like the source code for them is a comment, such that the breakpoints move to the first lines of code after them. This is with VS 2010.

    I can't post the exact code but it looks something like this:

    Code:
    // In .h file
    class OuterClass
    {
        class InnerClass;
        // Other stuff...
    };
     
    // In .cpp file
    class OuterClass::InnerClass
    {
    public:
        // Copy constructor
        InnerClass(InnerClass const & rhs)
        :
            m_WrapperAroundHugeMemberDataStructure(StaticConstIntegerId)
        {
            *this = rhs;
        }
        // Move constructor
        InnerClass(InnerClass && rhs)
        :
            m_WrapperAroundHugeMemberDataStructure(StaticConstIntegerId)
        {
            m_WrapperAroundHugeMemberDataStructure.SwapHugeData(&rhs.m_WrapperAroundHugeMemberDataStructure);
        }
        // Destructor
        ~InnerClass(void) {}
        // Other stuff...
    };
    When I set a breakpoint anywhere in the move constructor, the breakpoint jumps down to the destructor.

    The same thing happens with the move assignment operator in this class. I have another class with a move constructor and move assignment which has the same problem, and it is also an inner class.

    Am I doing anything obviously wrong here? Do move constructors have some subtlety when used with inner classes?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: move constructor is ignored?

    If your code never actually invokes the move constructor, then it's possible it could be optimized out.

  3. #3
    Join Date
    Mar 2006
    Posts
    151

    Re: move constructor is ignored?

    Thank you for your interest and response. Looking at it closer, I think you're right. I wrote this a couple of years ago and tried to pass everything around with pointers when possible and I'm using reference counting in the container class. I didn't think I had been that thorough!

    I did find one additional oddity in that if the inner class in my previous post is A, then A contains a collection of B and B contains a collection of C. Class C is the other inner class previously mentioned where the move constructor and move assignment are apparently optimized out. I realized I should also add a move constructor and move assignment operator to class B. In those, I'm using std::move to try to deliberately invoke the move operators I had already added to C. When I do that, I can successfully add a breakpoint to the move operator in B, but as judged by still not being able to set a breakpoint in C, its move operator is still apparently optimized out!? Also, the breakpoint in B is never hit when I do a test run, even though I can set it, but that’s probably just because the move code in A is never called.


  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: move constructor is ignored?

    Perhaps if you distilled your test code into a simple, compilable package we could offer more insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured