Microsoft KB Archive/319797

= 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 =

Article ID: 319797

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Windows CE eMbedded Visual C++, Version:4.0 3.0
 * Microsoft Encarta Reference Suite 2001
 * 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.



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); }

Keywords: kbbug kbpending KB319797

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.