FIX: C1001 Compiler Error When Virtual Function Used as a Parameter (259746)



The information in this article applies to:

  • Microsoft C/C++ Compiler (CL.EXE)
  • 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 Q259746

SYMPTOMS

The following C1001 compiler error can occur when a virtual function is used as a parameter:
test.cpp(18) : fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information

Error executing cl.exe.

Please refer to the "More Information" section for sample code that reproduces the error.

CAUSE

This is a bug in the compiler.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in the latest service pack for Visual Studio 6.0.

For additional information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed

To download the latest Visual Studio service pack, visit the following Microsoft Web site:

MORE INFORMATION

Following is sample code to reproduce the error:
// cl /c /GX ice.cpp

class TestClass
{
};

class ExampleClass
{
  public:	  
    void Compute(void);
    virtual TestClass&  TestFunction(void);
};

void ExampleClass::Compute(void)
{
  TestClass *test;
 
  test = new TestClass(TestFunction());
}

				


Following are three workarounds:

  1. Remove /GX (Enable exception handling) from compilation switches.
  2. Explicitly define a copy constructor for TestClass. For example:
       public:
       TestClass( TestClass&  );
    						
  3. Introduce a temp variable of type TestClass, as follows:
    void ExampleClass::Compute(void)
    {
      TestClass *test;
     
      TestClass temp = TestFunction();
      test = new TestClass(temp);  
    }
    						

Modification Type:MinorLast Reviewed:12/12/2005
Keywords:kbBug kbCPPonly kbfix kbLangCPP kbVC600fix kbVS600sp4fix kbVS600sp5fix KB259746