clang3.1で問題が発生しています。この特定の問題は、GCC4.2では発生しません。発生するエラーの例を次に示します。
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string>
typedef unsigned short char16_t;
typedef char16_t TCHAR;
typedef std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> > wstringT;
template<class T>
inline wstringT MyTestFunction(const T& source)
{
std::wstringstream out;
out << source ;
return out.str(); // error occurs here
};
エラーメッセージには次のように記載されています。
No viable conversion from '__string_type' (aka 'basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >') to 'wstringT' (aka 'basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR> >')
コードはコンパイラフラグ-fshort-wcharを使用してコンパイルされます。これは、wchar_tを16ビットのunsignedshortに変換することになっています。XCodev4.3.2でコードをコンパイルしています。