BUG: Incorrect Function Name Binding in Function Templates

Last reviewed: July 24, 1997
Article ID: Q138567
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0,

         4.1, 4.2, 5.0
    

SYMPTOMS

Given a function template G whose definition includes a function call to F that does not depend on a template parameter, the compiler does not bind function names at the point of the template definition. Instead the compiler binds them when the function template is instantiated. This could cause unexpected runtime results.

CAUSE

This is a fairly recent change to the ANSI C++ working paper. The current version of the Microsoft compilers do not support this feature.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Based on the ANSI C++ working paper draft (14.2.7), if a name can be bound at the point of the template definition and it is not a function called in a way that depends on a template parameter, it will be bound at the template definition point and the binding is not affected by later declarations.

Sample Code to Demonstrate Problem

   /* Compile options needed: Default
   */

   #include <iostream.h>

   void F(char)  { cout << "In F(char)" << endl; }

   template <class T>
   void G( T t )
   {
       F(1);   // F() is not dependent on T or t
   }

   void F(int) { cout <<"In F(int)" << endl; }

   void main()
   {
       G(2);
       G('a');
   }

   /* The output from the program */

   In F(int)
   In F(int)

   /* The output should be */

   In F(char)
   In F(char)


Additional query words: 9.00 10.00 10.10 10.20
Keywords : CPPIss vcbuglist400 vcbuglist500
Version : 2.0 2.1 2.2 4.0 4.1 4.2
Platform : NT WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.