BUG: Debugger Cannot Distinguish Between Template Functions and Overloaded Functions with Same Names (314280)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ .NET (2003)

This article was previously published under Q314280

SYMPTOMS

If a template function has the same name and scope as a non-template (overloaded) function, the Microsoft Visual Studio .NET debugger cannot distinguish between the functions when the debugger sets a breakpoint.

RESOLUTION

If you can choose a specialized template, do not use a non-template function overload. For example, use the definition in the following code:
template < > double templatefunc(double var){ ... }
				

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Visual Studio .NET, and then create a Managed C++ Empty Project in the Microsoft Visual Studio .NET integrated development environment (IDE).
  2. Add a Visual C++ source file to the project, and then add the following code to the source file:
    template<typename Type>
    Type templatefunc(Type var)
    { 
    	Type xx = var;
    	return var;
    }
    
    double templatefunc(double var)
    { 
    	double dblVar = var / 10;	
    	return dblVar;
    }
    
    void main()
    {	
    	templatefunc(1.2);	
    	templatefunc('a');
    	templatefunc(12);
    	
    }
    					
  3. Compile the project.
  4. Right-click the Type templatefunc(Type var) function, and then click New Breakpoint.
  5. In the New Breakpoint dialog box, click OK.
  6. In the Choose Breakpoints dialog box, click All, and then click OK.
  7. On the Debug menu, point to Windows, and then click Breakpoints.
  8. In the Breakpoints dialog box, notice that two breakpoints appear (templatefunc and templatefunc(double)). Press F5.
When the Breakpoints dialog box appears, notice that two different breakpoints appear to have been hit at the same time. A plus sign (+) appears in front of the first templatefunc breakpoint. If you expand the plus sign (+), another templatefunc(double) breakpoint appears. Both functions show a hit count of 1.

The bottom templatefunc(double) breakpoint should not appear in the dialog box.

Modification Type:MinorLast Reviewed:5/28/2003
Keywords:kbBug kbDebug kbNativeAttributes kbnofix KB314280