libstdc++/2985: inserter and extractor for std::complex can only be used on simple streams.
theonetruekenny@yahoo.com
theonetruekenny@yahoo.com
Mon May 28 14:56:00 GMT 2001
>Number: 2985
>Category: libstdc++
>Synopsis: inserter and extractor for std::complex can only be used on simple streams.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon May 28 14:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: theonetruekenny@yahoo.com
>Release: gcc-3_0-branch 2001-05-28
>Organization:
>Environment:
online compiler
>Description:
The inserter and extractor for complex<> cannot be used for streams other then ostream (basic_ostream<char, char_traits<char> >) and istream (basic_istream<char, char_traits<char> >).
The reason for this is that the template definition for these operators lives in the implementation file only, so these operators cannot be implicitly instantiated from another translation unit, resulting in final link errors due to unresolved references.
>How-To-Repeat:
#include <complex> // for std::complex
#include <string> // for std::char_traits<char> definition
#include <sstream> // for std::basic_ostringstream
#include <iostream> // for std::cout
struct my_char_traits : public std::char_traits<char>
{
};
typedef std::basic_ostringstream<char, my_char_traits> my_sstream;
int main()
{
my_sstream sstr;
std::complex<double> x( 3, 4 );
sstr << x; // this should instantiate an inserter for writing to my_sstream
std::cout << sstr.str().c_str();
return 0;
}
>Fix:
Make the template definition for the inserter and extractor visible from a #include <complex>. Add declarations for the explicit instantiations on ostream and istream to <complex>.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list