BUG: C1001 or C2434: Using Templates in Default ArgumentsID: Q140188
|
The compiler generates either an internal compiler error C1001 or a C2434 error when using the Minimal Rebuild option with code that contains:
fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 899)
-or-
error C2434: cannot convert default argument from 'type1' to 'type2'
The 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
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
The 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.
/* 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: kbVC400bug 10.00 10.10 10.20
Keywords : kbCompiler kbCPPonly kbVC kbVC500bug kbVC600bug
Version : winnt:4.0,4.1,4.2,5.0,6.0
Platform : winnt
Issue type : kbbug
Last Reviewed: May 17, 1999