By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,501 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,501 IT Pros & Developers. It's quick & easy.

Sanity Check

P: n/a
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;
}
Is this a bug?
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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?

Best

Kai-Uwe Bux

Feb 17 '06 #2

P: n/a
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...
Feb 17 '06 #3

P: n/a
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


Well, it does warn:

In copy constructor 'mystream::mystream(const mystream&)':
warning: base class 'struct std::basic_ios<char, std::char_traits<char> >'
should be explicitly initialized in the copy constructor

This is probably due to virtual inheritance being involved.

Feb 17 '06 #4

P: n/a
Rolf Magnus wrote:
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


Well, it does warn:

In copy constructor 'mystream::mystream(const mystream&)':
warning: base class 'struct std::basic_ios<char, std::char_traits<char> >'
should be explicitly initialized in the copy constructor

This is probably due to virtual inheritance being involved.


I can't seem to make it work, how should I go about initialising that base?

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.