BUG: Class Access Specifier Is Ignored When Temporary Objects Are Created (263637)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q263637

SYMPTOMS

The compiler incorrectly uses private or protected constructors when temporary class objects are created.

NOTE: The compiler generates a C4248 warning if compiled with the /W3 or /W4 compiler switch.

Please refer to the sample code in the "More Information" section for details.

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

The following sample code demonstrates the bug:
// Test.cpp
// Compiler option needed: /GX
class A
{
protected:
    A(int i) : m_i(i) {}
private:
    int m_i;
};

int main()
{
 //A a(8); // Error C2248 here, as expected.
 A(8);	// No error here. 
        // Produces warning C4248 with compiler switch /W3 or /W4.    

    try
    {
        throw A(8); // No error here also. 
               // Produces warning C4248 with compiler switch /W3 or /W4.
    }
    catch (A& a)
    {
    }

    return 0;
}

				

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbBug kbCompiler kbCPPonly KB263637