BUG: An Access Violation Occurs When You Use the /Og Switch for a Call That Passes an Object That Is Returned by a Static Member (319797)



The information in this article applies to:

  • Microsoft Windows CE eMbedded Visual C++, Version:4.0 3.0
  • Microsoft Windows CE Platform Builder 3.0
  • Microsoft Windows CE Platform Builder 4.0

This article was previously published under Q319797

SYMPTOMS

When an application makes a call and uses a parameter that is the result of a static member function, or uses a parameter that is a result of a non-member function that is returning an object, the application may generate an access violation.

CAUSE

Global optimization may push an incorrect pointer for the object parameter in the call. Subsequent use of this object pointer in the callee may result in corrupted memory.

RESOLUTION

Turn off global optimization for the module or function that encounters these problems.

To turn off global optimization, use one of the following methods:
  • Use the /Og- switch.
  • Do not include /Og or switches that use it, such as /Ox.
  • Use the IDE compiler optimization project settings.
  • Use #pragma optimize.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

struct ClassA
{
	virtual ~ClassA()
	{
	}

	static ClassA CreateObject() 
	{ 
		return ClassA(); 
	}
};

void fn2( ClassA a , int* pi )
{
	*pi = -1;
}

void main()
{
	int i;

	fn2( ClassA::CreateObject(), &i);
}
				

Modification Type:MinorLast Reviewed:8/18/2005
Keywords:kbbug kbpending KB319797