Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I set added some code to a C++ project that seemed to work fine, and it blew up. So I added some breakpoints.

I found that Visual Studio Express 2013 was jumping directly into the middle of a routine (not a constructor), then meandering about a few places, including many blank lines. So googling said to delete the SUO, which I did. Also, I'm in debug version, and those seem like only real solutions put forth.

In the middle of that, I commented out the lines that resulted in the bug. Visual Studio STILL steps through the funky lines (and they occurred before the lines I commented, so my comments shouldn't have made a difference in that aspect). But the program doesn't crash.

Should I be concerned about this funky behavior? I know I've seen VS 'catch' breakpoints before, usually in constructors, without going through the entire constructor, and it seemed to not be an issue in those cases.

If it is cause for concern, what should I be looking for?

Thanks,
David
Posted
Updated 12-Jun-14 13:00pm
v2
Comments
Member 1577551 12-Jun-14 21:03pm    
you might commented the code while debugging. and continued to run from there. That might causes that issue.

1 solution

It seems to have been a bug in Visual Studio 2013 itself. Curious if anyone with it can confirm on their installations, but it boiled down to in-header initialization of enums causing the debugger to go wonky, indicating probable bad code generation. To replicate, here's the smallest setup:

Create a new Visual C++ General solution empty project. Add a 'main' unit to it, or whatever you want to call it. Paste the following:
C#
#include "Object.h"
#include <iostream>

int main() {
   Junk * junk = NULL;
   Object o(junk);

   int dummy;
   std::cout << std::endl << "Press a key and 'Enter' to quit ";
   std::cin >> dummy; //Total junk way to do this, but good enough for testing
   return 0;
   }

Add an 'Object.cpp' file:
C#
#include "Object.h"

Object::Object(Junk * junk) : junkC(junk) { //Breakpoint on this line.

   }


bool Object::doSomething() {
   return true;
   } //Debugger jumps to here!!!  Wonky!

And an "Object.h"
C#
#pragma once

class Junk; //Forward declaration (but left incomplete for example)

class Object {
   private:
      Junk * junkC;

   public:
      enum Style { ThreeD, Flat, Shadow } containerStyleC = ThreeD;

      Object(Junk * junk);

      bool doSomething();
   };

Put a breakpoint at Object::Object(Junk*)... When it is hit, do a 'step into.' The next line the debugger goes to is the end of the 'doSomething' block.

If the enum initialization is performed in the cpp file's class initialization list, the debugger steps as expected. I tried reporting this through the 'Report a bug' option in VS, but it hasn't appeared yet, although there may have been one step I didn't complete. By the fact it shows I have no submissions, I'm guessing I missed a step, but I'll wait a while and maybe it will appear.
 
Share this answer
 
v3
Comments
David O'Neil 13-Jun-14 5:27am    
The report went through and MS has confirmed the buggy behavior. Time for some sleep!

Interestingly, the unit that this reared its head on now refuses to have any in-header initializations in it without buggy behavior. Made for a rather long initializer list (25 members) - yuck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900