Earlier quoted context omitted.
> Template instantiations are duplicated even for types where the instantiations could have identical code. compilers and linkers had identical code folding optimizations for a looooong time (20+ years for msvc, a decade or so for GNU gold (--icf option) and GCC (-fipa-icf))
I was going to reply with a similar comment, but I'm unable to actually get this to happen when I tried it now: https://godbolt.org/z/4VkEQc . Perhaps the optimization needs more work?
On my machine I get no unsigned instantiation, only the signed one :
$ objdump -D a.out | c++filt | grep foo
563: e8 21 01 00 00 callq 689 (int)>
56c: e8 18 01 00 00 callq 689 (int)>
0000000000000689 (int)>:
and the main : 0000000000000560 :
560: 53 push %rbx
561: 31 ff xor %edi,%edi
563: e8 21 01 00 00 callq 689 (int)>
568: 31 ff xor %edi,%edi
56a: 89 c3 mov %eax,%ebx
56c: e8 18 01 00 00 callq 689 (int)>
571: 0f b6 d3 movzbl %bl,%edx
574: 48 8d 3d b1 01 00 00 lea 0x1b1(%rip),%rdi # 72c
57b: 0f b6 f0 movzbl %al,%esi
57e: 31 c0 xor %eax,%eax
580: e8 cb ff ff ff callq 550
585: 31 c0 xor %eax,%eax
587: 5b pop %rbx
588: c3 retq
589: 00 00 add %al,(%rax)
58b: 00 00 add %al,(%rax)
58d: 00 00 add %al,(%rax)