[LLVMbugs] [Bug 20960] New: Linker errors on std::getline when including only <string> and not <istream>

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Sep 16 08:53:01 PDT 2014


            Bug ID: 20960
           Summary: Linker errors on std::getline when including only
                    <string> and not <istream>
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pbos at google.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

I believe this is in current ToT, we saw errors within a month in webrtc
requiring us to include <istream> in chromium.

We use a library that accepts istreams and uses getline, it doesn't define any
istreams itself so it didn't have to include istream but rather accept
references provided externally.

As getline seems to be instantiated in istream in libc++ this causes linker

#include <string>

std::istream& foo_getline(std::istream& is, std::string& str, char delim) {
  return std::getline(is, str, delim);

int main() {
  std::string foo;
  // expecting runtime crash not linker error
  foo_getline(*(std::istream*)(NULL), foo, ' ');

$ clang++ --stdlib=libc++ foo.cc
Undefined symbols for architecture x86_64:
  "std::__1::basic_istream<char, std::__1::char_traits<char> >&
std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char>
>(std::__1::basic_istream<char, std::__1::char_traits<char> >&,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >&, char)", referenced from:
      foo_getline(std::__1::basic_istream<char, std::__1::char_traits<char> >&,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >&, char) in foo-ATxcEi.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This invocation is on a colleague's MacBook Pro, unknown version. We did see
this in r216548 in webrtc last I checked and had to use a workaround, so I
believe it's still present.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140916/e48f643b/attachment.html>

More information about the llvm-bugs mailing list