Microsoft KB Archive/315948

= BUG: C1001 Error When You Use a Global Variable as a Template Argument =

Article ID: 315948

Article Last Modified on 4/11/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition

-



This article was previously published under Q315948



SYMPTOMS
When you pass a reference to a global variable as a template argument, you may receive the following compiler error (or a similar one):

repro.cpp(3): fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'f:\vs70builds\9466\vc\Compiler\Utc\src\P2\main.c', line 146)

Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information

You receive this error message only if you compile without using precompiled headers.



CAUSE
Because of a known bug, the compiler cannot generate correct code for a construct. In this case, the compiler cannot resolve the global variable.



RESOLUTION
To work around this problem, declare the variable at global scope, either in a separate header file, or in the global scope of the file in which the file is referenced.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
The following sample code, when compiled, reproduces the problem:

//Repro.cpp template  void Test {

*i = 0;

}

//int i; //Uncomment this line to resolve this problem.

int main {  extern int i;/*This would be okay if this was at global scope.*/ Test<&i>;

} You can run the following command at the command prompt to get this error:

cl /TP repro.cpp

When you use the Microsoft Visual Studio .NET Integrated Development Environment (IDE) to build this code, make sure that you do not use precompiled headers. To set this compiler option in the Visual Studio .NET IDE, follow these steps:
 * 1) In the Solution Explorer pane of the project, right-click the project name, and then click Properties.
 * 2) In the left pane, click the C/C++ folder.
 * 3) Click the Precompiled Headers node.
 * 4) In the right pane, click Create/Use Precompiled Header, and then click Not Using Precompiled Headers.

Keywords: kbbug kbfix kbcompiler KB315948

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.