FIX: C1001 on Cast to Base from Derived Friend Class (148255)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Professional Edition 4.0
  • Microsoft Visual C++, 32-bit Professional Edition 4.1
  • Microsoft Visual C++, 32-bit Professional Edition 4.2
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • Microsoft Visual C++, 32-bit Learning Edition 4.0
  • Microsoft Visual C++, 32-bit Learning Edition 4.2

This article was previously published under Q148255

SYMPTOMS

When an argument in a function call is passed by value and is cast to a base class from a derived class that is also a friend of the base class, the compiler generates this error:
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file '\school.tp3\test\c10\src\P2\386\codegen.c', line 359)
This occurs only when C++ exception handling is enabled (/GX) and the base class defines a destructor.

RESOLUTION

There are several workarounds:

  • Pass the class by reference. -or-

  • Remove the cast. It is unnecessary. -or-

  • Do not use the /GX compiler option if exception handling isn't required.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.

MORE INFORMATION

Sample Code to Reproduce Problem

  /* Compile options needed: /GX
   */ 

   class  Cbase {
      friend class Cfriend;
   public:
      ~Cbase( void ) {}
   };


   class Cfriend : public Cbase {};

   void f(Cbase z){}
   //   Workaround 1,pass by reference instead of by value
   //void f(Cbase& z) {}

   void main() {
      Cfriend P;
      // INTERNAL COMPILER ERROR on the following line
      f((Cbase)P);
   //   Workaround 2, do not use a cast.
   //   f(P);
   };
				

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbbug kbCompiler kbCPPonly kbfix kbProgramming KB148255