Bug 199114 - operator << (ostream &, const string &) linker problem
Summary: operator << (ostream &, const string &) linker problem
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2015-04-02 14:46 UTC by hartmut.brandt
Modified: 2016-08-08 07:33 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description hartmut.brandt 2015-04-02 14:46:44 UTC
<string> forward declares a template for the output operator, but this template is nowhere defined. Instead <ostream> provides an inline definition for that template. This leads to the following program not linking:

#include <iostream>

void foo(std::ostream &);

int main() {

#include <string>
#include <iosfwd>

void foo(std::ostream &os)
  os << std::string("a");

The linker will give an undefined symbol for the operator <<. The reason is that <string> forward declares the template which is not defined neither in <string> nor in the librarie's string.cc. Because of the forward declaration y.cc happily compiles with an undefined reference in the obj-file.

When including <ostream> in y.cc, the linker is successful since there is a inline template definition in <ostream>. According to my reading of the standard this is wrong - the defintion should be in <string> or string.cc should have an instantiation of the template for char and wchar_t.

This is probably an upstream issue?
Comment 1 David Chisnall freebsd_committer 2015-05-17 12:19:48 UTC
This definitely looks like an upstream issue.  Would you mind filing a bug on LLVM's bug tracker?