BUG: C1001 or C2434: Using Templates in Default ArgumentsLast reviewed: July 24, 1997Article ID: Q140188 |
The information in this article applies to:
SYMPTOMSThe compiler generates either an internal compiler error C1001 or a C2434 error when using the Minimal Rebuild option with code that contains:
CAUSEThe error occurs when processing the non-trivial default argument of a member function of a class that requires instantiating a template class for the first time. The error occurs when the compiler is forced to instantiate a template class for the first time in a default-argument expression because it needs to record information about the class for Minimal Rebuild purposes. One function is destroying data required by a function that is further down the call stack. The compiler generates a syntax error depending on how it interprets the destroyed data. If the compiler cannot make sense of the destroyed data, it will generate an Internal Compiler Error C1001. Depending on the code, the errors C1001 or C2434 may only occur when using one or more of these compiler options:
/Gm Enable Minimal Rebuild /GX Enable Exception Handling /Zi Create CodeView type Debug Information in a PDB file RESOLUTION
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe following sample code demonstrates the problem and generates the incorrect error C2434. The workaround in the comment below is to explicitly instantiate the template class (X<int>) before using it in a default- argument expression.
Sample Code
/* Compile options needed: NONE */ const int flag = 0; template<class T> struct X { void Xmf(int = flag) {} static int m_data; }; template<class T> int X<T>::m_data = 1; // Workaround: uncomment this explicit instantiation: // template struct X<int> ; struct Y { void Ymf(int = X<int>::m_data); // this line generates a C2434 }; void main(void) {} |
Additional query words: 10.00 10.10 10.20
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |