This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80662] libstdc++ basic_string casting oddity
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 08 May 2017 12:21:00 +0000
- Subject: [Bug c++/80662] libstdc++ basic_string casting oddity
- Auto-submitted: auto-generated
- References: <bug-80662-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80662
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|libstdc++ |c++
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And further:
namespace std
{
struct ostream
{
ostream& operator<<(const char*)
{
return *this;
}
};
#ifndef UNCONSTRAINED
// GCC 7 code
template<typename _Ostream, typename _Tp>
inline ostream&
operator<<(_Ostream&& __os, const _Tp&__x)
{
return __os;
}
#else
// GCC 6 code
template<typename _Tp>
inline ostream&
operator<<(ostream&& __os, const _Tp&)
{
return __os;
}
#endif
}
struct my_stream : public std::ostream {
template<typename T>
my_stream& operator<<(T&& value)
{
std::ostream::operator<<(value);
return *this;
}
};
int main()
{
my_stream& s = (my_stream{} << "hello world");
}
G++ chooses std::operator<<
Clang chooses my_stream::operator<<
EDG and VC++ say they're ambiguous.
Changing to component=c++, but I'm not convinced G++ is actually wrong here.