Kai-Uwe Bux wrote:
Ben Pope wrote:
Hi,
The following code compiles with Comeau Online, but not MSVC 8.0.
Comeau issues a warning that return 0 is unreachable.
#include <sstream>
#include <iostream>
class mystream : public std::stringstream {
public:
explicit mystream(::std::ios::openmode xW = in | out) :
std::stringstream(xW)
{}
mystream(const mystream& rhs) : std::stringstream() {
*this << rhs.str();
}
};
int main() {
mystream s1;
s1 << "foo";
mystream s2(s1);
throw s1; // can't access private copy constructor
return 0;
}
a) This code compiles just fine in g++-4.0.2
b) I do not see any reason, why it shouldn't compile.
Is this a bug?
Where?
Exactly. It can find the copy constructor when I do:
mystream s2(s1);
I get the following error (which I should have posted earlier) Line 20
is the throw statement, if I comment it, it compiles fine:
Compiling...
test.cpp
c:\development\cpp\smalltest\test\test\test.cpp(20 ) : warning C4673:
throwing 'mystream' the following types will not be considered at the
catch site
c:\program files\microsoft visual studio 8\vc\include\sstream(513) :
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access
private member declared in class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ios(151)
: see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_stringstream<_Elem,_Traits,_Alloc>::ba sic_stringstream(const
std::basic_stringstream<_Elem,_Traits,_Alloc> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
c:\program files\microsoft visual studio 8\vc\include\istream(916) :
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access
private member declared in class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ios(151)
: see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_iostream<_Elem,_Traits>::basic_iostrea m(const
std::basic_iostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\istream(842) :
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access
private member declared in class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ios(151)
: see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_istream<_Elem,_Traits>::basic_istream( const
std::basic_istream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ostream(581) :
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access
private member declared in class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\program files\microsoft visual studio 8\vc\include\ios(151)
: see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_ostream<_Elem,_Traits>::basic_ostream( const
std::basic_ostream<_Elem,_Traits> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
Build log was saved at
"file://c:\Development\Cpp\smalltest\test\test\Debug\Build Log.htm"
test - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Ben Pope
--
I'm not just a number. To many, I'm known as a string...