How does the linker handle identical template instantiations across translation units?

Viewed 3597

Suppose I have two translation-units:

foo.cpp

void foo() {
  auto v = std::vector<int>();
}

bar.cpp

void bar() {
  auto v = std::vector<int>();
}

When I compile these translation-units, each will instantiate std::vector<int>.

My question is: how does this work at the linking stage?

  • Do both instantiations have different mangled names?
  • Does the linker remove them as duplicates?
3 Answers
Related