473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sanity Check

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
4 3689
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lars Eighner | last post by:
I'm looking for a sanity checker for css comparable to tidy or weblint for html on a unoid system (FreeBSD). Any suggestions. -- Lars Eighner -finger for geek code- eighner@io.com...
9
by: Fred Ma | last post by:
Hello, I posted previously under the thread: How to break this up into streambuf/ostream I've asked our library to get "C++ IOStreams and Locales..." by A. Langer et al. Meantime, I've...
10
by: Bob Hollness | last post by:
OK. The below text is from the MySQL website. "When you connect to a MySQL server, you should use a password. The password is not transmitted in clear text over the connection. Password handling...
2
by: Jonathan Pryor | last post by:
I'm in need of a sanity check: is the following code valid C++? namespace foo { class NamespaceClass { }; } using namespace foo; class Bug_GlobalFriendDeclaresNamespaceClass {
32
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon );...
1
by: Dave | last post by:
Hi all, Is there a place to request a vulnerability check on a website? I had a problem that I think I fixed, but I'm fairly inexperienced with PHP (which is why I had the problem in the first...
6
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was...
0
by: cypher_key | last post by:
I'm C# and would like to get a sanity check from the group to ensure that I'm going down the right road. The first form in my mini-application is a search screen. I have an image of it here:...
2
by: eholz1 | last post by:
Hello CSS and StyleSheet members, I have decided to move away from Dreamweaver javascript rollover buttons, in favor of a CSS type rollover button. (hope that is ok). I plan to use PHP to...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.