missing basic_ostream::operator<<(basic_ostream&, const basic_string&) definition

Originator:gregory.pakosz
Number:rdar://12981426 Date Originated:01/09/2013
Status: Resolved:
Product:Developer Tools Product Version:Xcode Version 4.5.2 (4G2008a)
Classification:Bug Reproducible:Always
 
Summary:

building the following C++ snippet fails when building with 10.8sdk, with llvm-g++-4.2 and targeting 10.4

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
  stringstream ss;
  string s("hello world");

  ss << s;

  cout << ss.str() << endl;
  return 0;
}

Steps to Reproduce:

llvm-g++-4.2 -arch i386 -mmacosx-version-min=10.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk main.cpp

Expected Results:

The snippet should compile without errors.
Actual Results:

error: explicit instantiation of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’ but no definition available

Regression:

Notes:

I tracked the problem down to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/bits/basic_string.h line 2411

  template<typename _CharT, typename _Traits, typename _Alloc>
    inline basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __os,
	       const basic_string<_CharT, _Traits, _Alloc>& __str)
#if __TARGETING_4_0_DYLIB
    ; // __ostream_insert() not exported from libstdc++.6.0.4 dylib
#else
    {
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // 586. string inserter not a formatted function
      return __ostream_insert(__os, __str.data(), __str.size());
    }
#endif

As you can see, the template operator has no definition when __TARGETING_4_0_DYLIB is non 0.
__TARGETING_4_0_DYLIB is defined in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/c++/4.2.1/bits/os_defines.h line 111

#if __IPHONE_OS_VERSION_MIN_REQUIRED
	#define __TARGETING_4_0_DYLIB  0
#else 
	#define __TARGETING_4_0_DYLIB (__MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
#endif

Since I'm targeting 10.4 (our customers require Tiger support), __TARGETING_4_0_DYLIB gets defined to 1 preventing operator definition in bits/basic_string.h

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!