"C1001 Internal Compiler Error" Error Message When You Compile a Template Method That Does Not Have a Return Type (829604)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)
  • Microsoft Common Language Runtime (included with the .NET Framework 1.1)

SYMPTOMS

In Microsoft Visual C++ .NET 2003, if you implement a template method without specifying the return type, you receive the following error message from the Microsoft C/C++ Compiler (Cl.exe) when you try to compile your code:
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 2701)
Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information

RESOLUTION

To resolve this problem, specify the return type when you implement your template method. To do this, use code that is similar to the following modified code.

Note The following code is based on the sample that appears in the "More Information" section of this article. Therefore, this code may be different from your code.
template <class T, class S>
class tExample
{
	public:
		void fun1(void);
		void fun2(void);
};

template <class T, class S>
// To resolve C1001: INTERNAL COMPILER ERROR,
// add void as the return type to match the function prototype.
void tExample<T, S>::fun1(void) 
{ 
}

template <class T, class S>
// To resolve C1001: INTERNAL COMPILER ERROR,
// add void as the return type to match the function prototype.
void tExample<T, S>::fun2(void)
{
}

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

Note The compiler error message that you receive in Visual C++ .NET 2002 is different from the compiler error message that you receive in Visual C++ .NET 2003.

To reproduce this problem in Visual Studio .NET 2003, follow these steps:
  1. Open a Visual Studio .NET 2003 Command Prompt window. To do this, click Start, point to Programs, point to Microsoft Visual Studio .NET 2003, point to Visual Studio .NET Tools, and then click Visual Studio .NET 2003 Command Prompt.
  2. Run the following command at the Visual Studio .NET 2003 command prompt to open a file named templateExample.cpp in a text editor such as Notepad:

    notepad templateExample.cpp

  3. Paste the following code in the templateExample.cpp file:
    template <class T, class S>
    class tExample
    {
    	public:
    		void fun1(void);
    		void fun2(void);
    };
    
    template <class T, class S>
    tExample<T, S>::fun1(void)
    { 
    }
    
    template <class T, class S>
    tExample<T, S>::fun2(void)
    {
    }
  4. At the Visual Studio .NET 2003 command prompt, run the following command to try to compile the templateExample.cpp file:

    cl /c templateExample.cpp

    You receive the error message that appears in "Symptoms" section of this article.
If you try to compile the same code at a Visual Studio .NET 2002 command prompt, you receive the following compiler error messages:
error C2244: 'tExample<T,S>::fun1' : unable to match function definition to an existing declaration
a.cpp(5) : see declaration of 'tExample<T,S>::fun1' definition
'int tExample<T,S>::fun1(void)' existing declarations 'void tExample<T,S>::fun1(void)'
error C2954: template definitions cannot nest
a.cpp(15) : error C2244: 'tExample<T,S>::fun2' : unable to match function definition to an existing declaration
a.cpp(6) : see declaration of 'tExample<T,S>::fun2' definition 'int tExample<T,S>::fun2(void)' existing declarations 'void tExample<T,S>::fun2(void)'

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbfix kbCompiler kbProgramming kberrmsg kbcode kbbug KB829604 kbAudDeveloper