BUG: C1001 error occurs while accessing a property by using a smart pointer in a struct member (823929)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

SYMPTOMS

When you access a property through a smart pointer for a struct member, you may receive the following internal compiler error message:
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'f:\vs70builds\9466\vc\Compiler\CxxFE\sl\P1\C\toil.c', line 7021)
Note The file name, the full path, and the line number may vary with the compiler build that you use.

WORKAROUND

To work around this bug, copy the contents of the property that are accessed by a smart pointer to a temporary variable, and then use the copied value in a struct member. The following is the modified code:
#import "TestServer.dll" no_namespace
void main() {
        CoInitialize(NULL);
        IPtr p(__uuidof(C));
        struct s {
                int number;
                wchar_t* string;
        };
        wchar_t* str1 = p->a;
        wchar_t* str2 = p->b;
        s impl[2] = {
                {0, str1},
                {1, str2}
        };
	p = 0;
	CoUninitialize();
}

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 the Behavior

Create a Component Object Model (COM) Component

  1. Paste the following code in Notepad:
    #define _ATL_ATTRIBUTES 1
    #include <atlbase.h>
    #include <atlcom.h>
    [module(name=ldld)];
    [dispinterface]
    __interface I {
    	[id(1)] BSTR a;
    	[id(2)] BSTR b;
    };
    [coclass]
    struct C : I {
    	void put_a(BSTR x) {}
    	void put_b(BSTR x) {}
    	BSTR get_a() { return 0; }
    	BSTR get_b() { return 0; }
    };
    
  2. Save the file as TestServer.cpp in the c:\TestServer folder.
  3. Open the Visual Studio .NET command prompt.
  4. Change the directory to C:\TestServer. Run the following command at the command prompt to create a COM Server:
    cl /LD TestServer.cpp

Create a COM Client

  1. Open a new instance of Notepad, and then paste the following code:
    #import "TestServer.dll" no_namespace
    void main() {
            CoInitialize(NULL);
            IPtr p(__uuidof(C));
            struct s {
                    int number;
                    wchar_t* string;
            };	
            s impl[2] = {
                    {0, p->a},
                    {1, p->b}
            };
    	p = 0;
    	CoUninitialize();
    }
    
  2. Save the file as TestClient.cpp in the C:\TestServer folder.
  3. At the Visual C++ .NET command prompt, run the following command:
    cl /GX TestClient.cpp
    You may receive the compilation error that the "Symptoms" section describes.

Modification Type:MinorLast Reviewed:1/18/2006
Keywords:kberrmsg kbSmartPtr kbCompiler kbbug KB823929 kbAudDeveloper