C++ optimizer fails in debug with /O2 and /Zi - by Matthias Mayrock

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 613868 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 10/15/2010 2:32:49 AM
Access Restriction Public


The following code succeeds in debug version but fails when compiled in debug version with /O2. I know the mixture is not the most common use-case but we @Ableton use it to get our test suite run faster. It fails in VC2008 and VC2010. When it fails, one of the contained assertions triggers:

#include <assert.h>

template <typename T, int MAXSIZE> class TStaticArray
  __forceinline T& operator[] (int Index)
    assert(Index >= 0 && Index < MAXSIZE);
    return mArray[Index];
  __forceinline const T& operator[] (int Index) const
    assert(Index >= 0 && Index < MAXSIZE);
    return mArray[Index];

  T mArray[MAXSIZE];

class Foo
  void Bar(); 

  int mPatternLength;
  TStaticArray<int, 512>  mPattern;

  : mPatternLength(3)

void Foo::Bar()
  for (int Index = 0; Index < mPatternLength / 2; Index++)
    volatile int Value = mPattern[mPatternLength * 2 - Index - 1];
    mPattern[Index * 2 + 1] = Value;

int _tmain(int /*argc*/, _TCHAR* /*argv[]*/)
  Foo c;

	return 0;
Sign in to post a comment.
Posted by Microsoft on 11/30/2010 at 5:51 PM
This is a bug in the VC++ compiler and will be fixed in a future release. Until such time, you can work around this bug by disabling optimizations in the function that exhibits the issue.

You can use this MSDN resource for directions on how to selectively disable optimizations:


Mark Levine
Visual C++
Posted by Microsoft on 10/17/2010 at 7:48 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by Microsoft on 10/15/2010 at 3:21 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)