At Josuttis' and Vandevoorde, the famous book on templates, C ++ Templates: The Complete Guide , they discuss details regarding overloading function templates.
In one of their examples related to the discussion of function signatures and overloaded function templates, they represent the code that they describe in the following expressions:
This program is valid and produces the following output: (Note: Output shown below)
However, when I create and compile identical code in Visual Studio 2010, I get a different result. This makes me think that either the VS 2010 compiler is generating the wrong code, or Josuttis is incorrect that the code is valid.
Here is the code. (Josuttis 2003, section 12.2.1)
// File1.cpp
...
// File2.cpp
(Note the spread of type arguments in two definitions of template functions. Also, note that this call has no effect if the two type arguments are the same as for the two f1() functions in this code example.)
According to Yosuttis:
This program is valid and produces the following output: f1(T2, T1) f1(T1, T2)
When I create and run identical code without changes in the Visual Studio 2010 compiler, here is my result:
f1(T1, T2) f1(T1, T2)
In addition, I was wondering how it is possible for the compiler / linker to distinguish function f1 as created in file1.cpp, and function f1 as an instance in file2.cpp, given that (I think) the compiler discards all the βknowledgeβ about that these functions were created from templates and has only information (I think) of the function itself: void (char, char) , which is the same for both f1 functions.
Since (if I'm right) the signature of the function is identical in two translation units, I would think that this is an example of a violation of the One Definition Rule (ODR), and therefore it would be invalid C ++.
However, as I just noted, Josuttis and Vandevoorde claim that it is really C ++.
But since my compiled version of the same code gives different results than the Josuttis statement is the result, this seems to indicate that either VS 2010 is creating the wrong code, or Josuttis is wrong in this case (i.e. the code invalid and violates ODR).
Are Josuttis and Vandevoorde incorrect, or is VS 2010 producing the wrong output? Or is there some other explanation explaining the discrepancy between the conclusions of VS 2010 and the output of the Josuttis report?
It might seem interesting to demonstrate the disassembly of VS 2010 at the point at which each f1() called.
The first call to f1() (directly inside main() ):

The second call to f1() (from inside g() ):

Note that the address f1() chosen by the compiler in both cases is the same - 13E11EAh. For me, this indicates that, in fact, the compiler cannot distinguish between the two instantiated functions, and this is the case when the ODR is violated, so the code is invalid. C ++ and Josuttis have an error in their book. But this is just an indication. I dont know.
(I checked for errors on the book's website, and this example is not mentioned.)
ADD . In the request from the comment, I add the corresponding output from the .map file for this program, which shows the changed names / s used for f1 :

APPENDIX 2 Now that the question will be answered - the book of Josuttis is correct - I want to note that in the text of Josuttis in the same section (12.2.1) it is clearly outlined that defines a unique signature of the function, including the aspect of the template.
From the text (between other, expected things that determine the signature of a function), the TRANSFER GROUP is part of the signature of the function; for template functions (only), the RETURN TYPE is part of the function signature, and
0.6. Template parameters and template arguments if the function is generated from the function template.
Therefore - this is understandable. Information about templates should be maintained and monitored by the compiler even after creating a function template so that the compiler / linker follows the necessary special rules for templates (as in the case of code example in my question).