473,405 Members | 2,354 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,405 software developers and data experts.

Is there something wrong with this OO/STL code?

Hi,

the following is a boiled-down version of a problem
we're plagued with. It's still a rather complicated
class hierarchy, but if we remove one more item, the
problem disappears.
This is the class hierarchy ('v' indicates virtual
inheritance):

A
|
v
|
B
| \
v v
| \
C B_
| \ \
v v \
| \ \
D C_ |
| \ \ |
v v | |
| \ | |
E \|/
\ D_
\ |
\ |
\ |
\|
E_

In code:

#include <map>

struct A {virtual ~A() {}; bool b1;};
struct B : public virtual A {bool b2[21];};
struct C : public virtual B {};
struct D : public virtual C {};
struct E : public virtual D {};

struct B_ : public virtual B {};
struct C_ : public virtual C {};
struct D_ : public virtual D
, public C_
, public B_{};
struct E_ : public D_
, public E {};

int main()
{
typedef std::map< unsigned long, E_* > M;
M m;
E_* p = new E_();
m.insert( M::value_type( 1, p ) );
for( M::iterator it = m.begin(); it != m.end(); ++it ) {
delete (*it).second; // *1
(*it).second = NULL;
}
m.clear(); // *2
}

The problem is in the line marked with *2: With
CodeWarrior 9.4 on MacOS X, it crashs with an
access fault. When we debug into the call to
'clear()' it seems as if (due to the delete in
line *1), the map somehow is messed up.
We could reproduce the crash with CW9.3, which
also usees MSL as their std lib. We could not
reproduce it with CW8 (MSL), GCC3.3 (either
libstd or Dinkumware) and VC7.1 (Dinkumware).
I have verified that Comeau (Online) compiles
the code without any warnings or errors.

Now here's my question: Is there anything wrong
with the code or is this a bug in the MSL?

TIA,

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett

Jul 23 '05 #1
2 1213
Hendrik Schober wrote:
the following is a boiled-down version of a problem
we're plagued with. It's still a rather complicated
class hierarchy, but if we remove one more item, the
problem disappears.
This is the class hierarchy ('v' indicates virtual
inheritance):

A
|
v
|
B
| \
v v
| \
C B_
| \ \
v v \
| \ \
D C_ |
| \ \ |
v v | |
| \ | |
E \|/
\ D_
\ |
\ |
\ |
\|
E_

In code:

#include <map>

struct A {virtual ~A() {}; bool b1;};
struct B : public virtual A {bool b2[21];};
struct C : public virtual B {};
struct D : public virtual C {};
struct E : public virtual D {};

struct B_ : public virtual B {};
struct C_ : public virtual C {};
struct D_ : public virtual D
, public C_
, public B_{};
struct E_ : public D_
, public E {};

int main()
{
typedef std::map< unsigned long, E_* > M;
M m;
E_* p = new E_();
m.insert( M::value_type( 1, p ) );
for( M::iterator it = m.begin(); it != m.end(); ++it ) {
delete (*it).second; // *1
(*it).second = NULL;
}
m.clear(); // *2
}

The problem is in the line marked with *2: With
CodeWarrior 9.4 on MacOS X, it crashs with an
access fault. When we debug into the call to
'clear()' it seems as if (due to the delete in
line *1), the map somehow is messed up.
We could reproduce the crash with CW9.3, which
also usees MSL as their std lib. We could not
reproduce it with CW8 (MSL), GCC3.3 (either
libstd or Dinkumware) and VC7.1 (Dinkumware).
I have verified that Comeau (Online) compiles
the code without any warnings or errors.

Now here's my question: Is there anything wrong
with the code or is this a bug in the MSL?


There is nothing wrong with the code.

Have you tried to debug the library code to see where and when
the map gets "messed up"? That's what I'd do if I were to make
sure that 'MSL' is the culprit.

V
Jul 23 '05 #2
Victor Bazarov <v.********@comAcast.net> wrote:
[...]
There is nothing wrong with the code.

Have you tried to debug the library code to see where and when
the map gets "messed up"? [...]
Yes. -- And got lost in some proprietary
tree implementation. :) Honestly, if the
code is correct, I'll report thisas a bug
and let MW do the debugging.
V

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Luka Milkovic | last post by:
Hello, I have a little problem and although it's little it's extremely difficult for me to describe it, but I'll try. I have written a program which extracts certain portions of my received...
0
by: Steve | last post by:
Hi, Is there something fundamentally wrong with the following query? SELECT MAX(OrderID) AS Expr1 FROM Orders WHERE (MarketActionCode = 'S') AND (OrderLegCode = 'S') AND (Status = 'F') AND...
6
by: Vandana Rola | last post by:
Hello Everyone, I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript. What I am trying to do is creating a multiple answer...
6
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
3
by: Beemer Biker | last post by:
I started seeing huge amounts of error messages such as "Validation (XHTML 1.0 Transitional):" Element schema is not supported". There was nothing wrong with that for 3 weeks and suddenly there...
11
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke...
25
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
2
by: patrickdepinguin | last post by:
Hi, I use zlib to write data structures to a compressed file, using the gzwrite function. Afterwards I read the data back with gzread. I notice that this works well when the data written is not...
13
compman9902
by: compman9902 | last post by:
Hello, and thank you for hwlping me with this run-in with trouble. I am making a script for pig latin transulation, and there is something wrong with the "if" statement in line 51. Here is the code...
3
by: Peter Oliphant | last post by:
It's not necessary, but it would be nice if there was a way I could easily create something like a 'web browser form' or a 'display web page form' as forms in my application (in a Panel would be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.