FIX: C1001 or C2434: Using Templates in Default Arguments (140188)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q140188 SYMPTOMS
The compiler generates either an internal compiler error C1001 or a C2434
error when using the Minimal Rebuild option with code that contains:
- Classes that contain member functions that have default arguments of
type template class or member of template class.
- A Template class that contains member functions that have non trivial
default arguments (arguments that are not simple constants).
Even though the code is correct, the compiler generates one of the
following two errors:
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 899)
error C2434: cannot convert default argument from 'type1' to 'type2'
CAUSE
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
RESOLUTION- Re-order the code so that the first instantiation of the template class
does not occur in a default-argument expression. Make sure you have
provided definitions for all the member functions of the class template.
See the "More Information" section for an example.
-or-
- Turn off the Minimal Rebuild (-Gm) option. To do this:
- On the Build menu, click Settings.
- Select the Debug Version of the project.
- Click the C/C++ tab.
- Select Customize from the Category list.
- Clear the Enable Minimal Rebuild option.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
This problem was corrected in Microsoft Visual C++ .NET.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbBug kbCompiler kbCPPonly kbfix kbNoUpdate KB140188 |
---|
|