Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Apr 2015 14:46:44 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-standards@FreeBSD.org
Subject:   [Bug 199114] operator << (ostream &, const string &) linker problem
Message-ID:  <bug-199114-15@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=199114

            Bug ID: 199114
           Summary: operator << (ostream &, const string &) linker problem
           Product: Base System
           Version: 11.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: standards
          Assignee: freebsd-standards@FreeBSD.org
          Reporter: hartmut.brandt@dlr.de

<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:

x.cc
---
#include <iostream>

void foo(std::ostream &);

int main() {
  foo(std::cout);
}

y.cc
---
#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?

-- 
You are receiving this mail because:
You are the assignee for the bug.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-199114-15>