public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17648] New: template destrucktor was not called for inherited classes
@ 2004-09-24 8:10 hs at profiforms dot de
2004-09-24 8:13 ` [Bug c++/17648] " hs at profiforms dot de
` (21 more replies)
0 siblings, 22 replies; 23+ messages in thread
From: hs at profiforms dot de @ 2004-09-24 8:10 UTC (permalink / raw)
To: gcc-bugs
I've an unexpectet behavior while defining templates.
In my example I show only the error. Please do not think it's my program
itselfe.
Please compile and link the main.cpp whitout any additional files. The example
is complete.
What I'm doing here:
I step thousand of times through a function which create and destroy an object
includes an subobject.
The subobject is a child of an templete class.
On stdout you can see that the constructor was called but the the destructor
never.
On Borland and MS it runs well. Why not in g++?
--
Summary: template destrucktor was not called for inherited
classes
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hs at profiforms dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: same
GCC host triplet: found fore Linux Intel HP-UX Solaris
GCC target triplet: same
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] template destrucktor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
@ 2004-09-24 8:13 ` hs at profiforms dot de
2004-09-24 8:14 ` hs at profiforms dot de
` (20 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: hs at profiforms dot de @ 2004-09-24 8:13 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From hs at profiforms dot de 2004-09-24 08:13 -------
Created an attachment (id=7210)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7210&action=view)
the separated error in a short sample program
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] template destrucktor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
2004-09-24 8:13 ` [Bug c++/17648] " hs at profiforms dot de
@ 2004-09-24 8:14 ` hs at profiforms dot de
2004-09-24 9:08 ` [Bug c++/17648] template destructor " schwab at suse dot de
` (19 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: hs at profiforms dot de @ 2004-09-24 8:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From hs at profiforms dot de 2004-09-24 08:14 -------
Created an attachment (id=7211)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7211&action=view)
version file of g++
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
2004-09-24 8:13 ` [Bug c++/17648] " hs at profiforms dot de
2004-09-24 8:14 ` hs at profiforms dot de
@ 2004-09-24 9:08 ` schwab at suse dot de
2004-09-24 11:50 ` pinskia at gcc dot gnu dot org
` (18 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: schwab at suse dot de @ 2004-09-24 9:08 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Summary|template destrucktor was not|template destructor was not
|called for inherited classes|called for inherited classes
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (2 preceding siblings ...)
2004-09-24 9:08 ` [Bug c++/17648] template destructor " schwab at suse dot de
@ 2004-09-24 11:50 ` pinskia at gcc dot gnu dot org
2004-09-24 12:43 ` bangerth at dealii dot org
` (17 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-24 11:50 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-09-24 11:50 -------
This works on the mainline but I cannot test otherwise.
--
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (3 preceding siblings ...)
2004-09-24 11:50 ` pinskia at gcc dot gnu dot org
@ 2004-09-24 12:43 ` bangerth at dealii dot org
2004-09-24 13:01 ` [Bug c++/17648] [3.3 regression] " bangerth at dealii dot org
` (16 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: bangerth at dealii dot org @ 2004-09-24 12:43 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-09-24 12:42 -------
I can compile and link your program just fine with gcc versions
2.95.3, 3.2.3, 3.3.5, 3.4.2, and present mainline. The only
output I see at all is this:
g/x> /home/bangerth/bin/gcc-4*/bin/c++ x.cc
In file included
from /home/bangerth/bin/gcc-4.0-pre/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/backward/iostream.h:31,
from x.cc:2:
/home/bangerth/bin/gcc-4.0-pre/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section 17.4.1.2
of the C++ standard. Examples include substituting the <X> header for the
<X.h> header for C++ includes, or <iostream> instead of the deprecated header
<iostream.h>. To disable this warning use -Wno-deprecated.
The warning message should be selfexplanatory: since the 1998 standard, you
should use
#include <iostream>
instead of
#include <iostream.h>
Can you be more specific about what exactly the problem is that you are
seeing? German language descriptions would also be fine.
Thanks
Wolfgang
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (4 preceding siblings ...)
2004-09-24 12:43 ` bangerth at dealii dot org
@ 2004-09-24 13:01 ` bangerth at dealii dot org
2004-09-24 13:20 ` hs at profiforms dot de
` (15 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: bangerth at dealii dot org @ 2004-09-24 13:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-09-24 13:01 -------
Nevermind, I see it now -- one has to actually run the test.
So here is a reduced testcase:
-----------------------
#include <iostream>
extern "C" void abort ();
int counter = 0;
template <class T> struct ListT {
ListT() {
++counter;
std::cout << "constructor\n";
array=NULL;
}
~ListT() {
--counter;
std::cout << "destructor\n";
if(array)
delete array;
}
T *array;
};
class Object;
class ObjectList : public ListT<Object> {};
class Object {
ObjectList list;
};
void test() {
Object Test;
}
int main()
{
test();
if (counter != 0)
abort ();
}
----------------------------------
This works just fine with gcc 2.95.3, 3.2.3, 3.4.2 and mainline, but
it fails with 3.3.4 for which we get only one call to the constructor
but none for the destructor.
The actual bug in the compiler seems to be rather sensitive to what is
actually going on in ListT::~ListT. Maybe someone with more time on
their hands can find a shorter testcase without includes.
As for workarounds: if you move around some code, I can make the bug in
the compiler go away. You may be able to achieve the same in your
original code. Apart from that, many thanks for a nice and small testcase,
even if I didn't see at first what the problem was :-(
Thanks
Wolfgang
--
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |3.3.4
Known to work|4.0.0 |4.0.0 3.2.3 2.95.3 3.4.2
Last reconfirmed|0000-00-00 00:00:00 |2004-09-24 13:01:19
date| |
Summary|template destructor was not |[3.3 regression] template
|called for inherited classes|destructor was not called
| |for inherited classes
Target Milestone|--- |3.3.5
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (5 preceding siblings ...)
2004-09-24 13:01 ` [Bug c++/17648] [3.3 regression] " bangerth at dealii dot org
@ 2004-09-24 13:20 ` hs at profiforms dot de
2004-09-24 13:54 ` hs at profiforms dot de
` (14 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: hs at profiforms dot de @ 2004-09-24 13:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From hs at profiforms dot de 2004-09-24 13:20 -------
I new the C++ standard and usually I use namespaces std or -Wno-deprecated
for older sources. Plaece use for this example -Wno-deprecated.
The output when the program is running should be:
Constructor
Destructor
Constructor
Destructor
...
In g++ 3.3.1 on Linux Intel, SunOS und HP-UX the Output is:
Constructor
Constructor
...
Without destructor the program is feeding memory.
Meanwhile I've tested g++ 2.952 on an old 32-Bit HP-UX. On this system it's
working well.
Holger
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (6 preceding siblings ...)
2004-09-24 13:20 ` hs at profiforms dot de
@ 2004-09-24 13:54 ` hs at profiforms dot de
2004-09-26 16:11 ` bangerth at dealii dot org
` (13 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: hs at profiforms dot de @ 2004-09-24 13:54 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From hs at profiforms dot de 2004-09-24 13:54 -------
I've tested in my real program to write only one call in the template
desructor
template <class T> ListT<T>::~ListT()
{DeleteContent();
}//end of template <class T> ListT<T>::~ListT()
On Linux it works for some instances but not for all. On HP-UX it don't work
in all cases.
As workaround I switch to g++ 2.95.2 on all machines.
Holger
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (7 preceding siblings ...)
2004-09-24 13:54 ` hs at profiforms dot de
@ 2004-09-26 16:11 ` bangerth at dealii dot org
2004-09-27 3:26 ` giovannibajo at libero dot it
` (12 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: bangerth at dealii dot org @ 2004-09-26 16:11 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
Ever Confirmed| |1
Last reconfirmed|2004-09-24 13:01:19 |2004-09-26 16:11:54
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (8 preceding siblings ...)
2004-09-26 16:11 ` bangerth at dealii dot org
@ 2004-09-27 3:26 ` giovannibajo at libero dot it
2004-09-27 14:29 ` gdr at cs dot tamu dot edu
` (11 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-27 3:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-09-27 03:26 -------
A better workaround would be to switch to 3.4.2 on all machines.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (9 preceding siblings ...)
2004-09-27 3:26 ` giovannibajo at libero dot it
@ 2004-09-27 14:29 ` gdr at cs dot tamu dot edu
2004-09-28 13:44 ` gdr at gcc dot gnu dot org
` (10 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: gdr at cs dot tamu dot edu @ 2004-09-27 14:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at cs dot tamu dot edu 2004-09-27 14:29 -------
Subject: Re: [3.3 regression] template destructor was not called for inherited classes
"giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> writes:
| A better workaround would be to switch to 3.4.2 on all machines.
That is probably a good suggestion. I don't think this is going to be
fixed in 3.3.x. After 3.3.5, 3.3.6 will be the last for this year and
for the 3.3.x series.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (10 preceding siblings ...)
2004-09-27 14:29 ` gdr at cs dot tamu dot edu
@ 2004-09-28 13:44 ` gdr at gcc dot gnu dot org
2004-10-06 15:01 ` hs at profiforms dot de
` (9 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-09-28 13:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From gdr at gcc dot gnu dot org 2004-09-28 13:41 -------
Adjust milestone
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.3.5 |3.3.6
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3 regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (11 preceding siblings ...)
2004-09-28 13:44 ` gdr at gcc dot gnu dot org
@ 2004-10-06 15:01 ` hs at profiforms dot de
2004-10-28 3:49 ` [Bug c++/17648] [3.3/3.4 Regression] " giovannibajo at libero dot it
` (8 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: hs at profiforms dot de @ 2004-10-06 15:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From hs at profiforms dot de 2004-10-06 15:01 -------
I've tested also for gcc-3.4.2 on HP-UX. The bug is still exist.
This is the newest version I'm able to download as binary.
To build a newer mailstone as gcc on all platforms is not my profession.
It is too heavy for me.
I've recognized the error is not occored on gcc-3.2.3 on solaris. So I will
lock for gcc-3.2.3 precomiled binary for HP-UX, AIX, Tru64, and Linux.
Thanks
Holger
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (12 preceding siblings ...)
2004-10-06 15:01 ` hs at profiforms dot de
@ 2004-10-28 3:49 ` giovannibajo at libero dot it
2004-10-28 3:54 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: giovannibajo at libero dot it @ 2004-10-28 3:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-10-28 03:49 -------
OK, reported to be actual on 3.4.2 as well, on HP-UX at least. It looks like
some really weird problem, maybe latent on mainline. Can any of our testcase
reduction specialist try to extract a small testcase?
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |belyshev at lubercy dot com,
| |reichelt at gcc dot gnu dot
| |org
Known to fail|3.3.4 |3.3.4 3.4.2
Known to work|4.0.0 3.2.3 2.95.3 3.4.2 |4.0.0 3.2.3 2.95.3
Summary|[3.3 regression] template |[3.3/3.4 Regression]
|destructor was not called |template destructor was not
|for inherited classes |called for inherited classes
Target Milestone|3.3.6 |3.4.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (13 preceding siblings ...)
2004-10-28 3:49 ` [Bug c++/17648] [3.3/3.4 Regression] " giovannibajo at libero dot it
@ 2004-10-28 3:54 ` pinskia at gcc dot gnu dot org
2004-10-28 15:30 ` reichelt at gcc dot gnu dot org
` (6 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-28 3:54 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.4.2 |3.4.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (14 preceding siblings ...)
2004-10-28 3:54 ` pinskia at gcc dot gnu dot org
@ 2004-10-28 15:30 ` reichelt at gcc dot gnu dot org
2004-10-28 16:33 ` giovannibajo at libero dot it
` (5 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-10-28 15:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From reichelt at gcc dot gnu dot org 2004-10-28 15:30 -------
Here's a condensed version of Wolfgang's testcase:
====================================
int i=1;
class A;
template<int> struct B
{
A *p;
~B()
{
--i;
p=0;
if(p) delete p;
}
};
class C : B<0> {};
class A { C c; };
int main()
{
{ C c; }
return i;
}
====================================
On i686-pc-linux-gnu this returns 0 except for gcc 3.3.x where it returns 1.
However, I'm unsure whether this is valid at all:
If I remove the template, the compiler says:
x.cc: In destructor `B::~B()':
x.cc:13: warning: possible problem detected in invocation of delete operator:
x.cc:13: warning: invalid use of undefined type 'struct A'
x.cc:3: warning: forward declaration of 'struct A'
x.cc:13: note: neither the destructor nor the class-specific operator delete
will be called, even if they are declared when the class is defined.
The warning seems to be justified. To construct A's destructor one needs C's,
which needs A's via C's base class B<0>.
Maybe we are invoking undefined behavior here, so looking for a bug would
become moot.
Comments?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (15 preceding siblings ...)
2004-10-28 15:30 ` reichelt at gcc dot gnu dot org
@ 2004-10-28 16:33 ` giovannibajo at libero dot it
2004-11-01 0:14 ` mmitchel at gcc dot gnu dot org
` (4 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: giovannibajo at libero dot it @ 2004-10-28 16:33 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-10-28 16:32 -------
Volker, thanks for the reduction. The bug is hideous, look at this:
----------------------------
class A;
template <int> struct B
{
A* a;
~B() { delete a; }
};
struct A {
B<0> b;
};
----------------------------
When B's destructor is instantiated, A must be a complete type, otherwise this
invokes undefined behaviour.
Now, B's destructor is instantiated when A's destructor is instantiated
(because it implicitally calls it), and at that point A is probably complete
(because its definition is already finished). At least, I think so.
This requires some legal help: is it true that B's destructor cannot be
instantiated before its first use, which is in the implicit A's destructor? Is
it true that, by the time that A's destructor is synthesized, A is a complete
type?
Either we have a codegen bug, or we are missing the warning (and probably
missing it also from 3.4 and mainline, even if we *happen* to generate the
correct code).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (16 preceding siblings ...)
2004-10-28 16:33 ` giovannibajo at libero dot it
@ 2004-11-01 0:14 ` mmitchel at gcc dot gnu dot org
2004-12-17 11:12 ` SWElef at post dot sk
` (3 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-11-01 0:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2004-11-01 00:14 -------
Postponed until GCC 3.4.4.
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.4.3 |3.4.4
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (17 preceding siblings ...)
2004-11-01 0:14 ` mmitchel at gcc dot gnu dot org
@ 2004-12-17 11:12 ` SWElef at post dot sk
2004-12-20 17:09 ` SWElef at post dot sk
` (2 subsequent siblings)
21 siblings, 0 replies; 23+ messages in thread
From: SWElef at post dot sk @ 2004-12-17 11:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From SWElef at post dot sk 2004-12-17 11:12 -------
AFAICT the code in comment #5 is well-formed.
std:12.4/5: An implicitly-declared destructor is implicitly defined
when it is used to destroy an object of its class type...
Thus, the declaration+definition of class ObjectList only declares
ObjectList::~ObjectList() and the implementation is not permitted
to define it yet, which also means that the implementation is not
permitted to instantiate ListT<Object>::~ListT(). The definition
of class Object again only declares Object::~Object(). The first
place where a destructor is used is the body of the function "test"
where Object::~Object() must be implicitly defined. It forces the
implicit definition of ObjectList::~ObjectList() and finaly the
instantiation of ListT<Object>::~ListT(). At this point, however,
the class Object is already defined so there is no undefined
behaviour. (See also std:14.7.1/9 which forbids early instantiation
of non-virtual member functions including the discussed dtor.)
Note that during the instantiation of ListT<Object>::~ListT()
the expression "delete array;" involves a call to _inline_
Object::~Object() that has not been defined yet (it is just waiting
to be defined after its member's dtor's implicit definition is
completed). I can imagine that this may cause some problems for
the implementation but it does not affect the validity of the code.
(Note in 7.1.2/4: a call to the inline function may be encountered
before its definition appears in the translation unit.)
Regards,
Vladimir Marko
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (18 preceding siblings ...)
2004-12-17 11:12 ` SWElef at post dot sk
@ 2004-12-20 17:09 ` SWElef at post dot sk
2005-05-10 3:20 ` mmitchel at gcc dot gnu dot org
2005-05-10 5:55 ` pinskia at gcc dot gnu dot org
21 siblings, 0 replies; 23+ messages in thread
From: SWElef at post dot sk @ 2004-12-20 17:09 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From SWElef at post dot sk 2004-12-20 17:09 -------
(In reply to comment #13)
> Here's a condensed version of Wolfgang's testcase:
> ====================================
> int i=1;
> class A;
> template<int> struct B
> {
> A *p;
> ~B()
> {
> --i;
> p=0;
> if(p) delete p;
> }
> };
> class C : B<0> {};
> class A { C c; };
> int main()
> {
> { C c; }
> return i;
> }
This is not a "condensed version of Wolfgang's testcase". While Wolfgang's
testcase is well-formed, your is ill-formed. The difference is that it uses
a pointer to object of _non-dependent_ incomplete type, i.e. it is invalid
according to tc1:14.6/7:
Knowing which names are type names allows the syntax of every template
definition to be checked. No diagnostic shall be issued for a template
definition for which a valid specialization can be generated. If no valid
specialization can be generated for a template definition, and that
template is not instantiated, the template definition is ill-formed,
no diagnostic required. If a type used in a non-dependent name is
incomplete at a point at which a template is defined but is complete
at the point at which an instantiation is done, and if the completeness
of that type affects whether or not the program is well-formed or affects
the semantics of the program, the program is ill-formed; no diagnostic
required. [Note: ...]
The details are very subtle because the template definition is not ill-formed
by itself. std:5.3.5/5 says
If the object being deleted has incomplete class type at the point of
deletion and the complete class has a non-trivial destructor or a
deallocation function, the behavior is undefined.
Thus, it would be well defined if the class A was later completed with
trivial destructor and no class specific deallocation function.
It is ill-formed because class A was incomplete at the point of definition
of B<int>::~B(), it was later defined with non-trivial destructor _and_
B<0>::~B() (with "delete p;") was instantiated. For example the snippet from
comment #14 _as short as it is_ is AFAICT well-formed.
In this context it might be important to note that starting from gcc3.4
we have the two phase lookup. gcc3.4+ should be able to issue the same
warning for the expression "delete p;" as for an ordinary delete expression
involving an incomplete type.
Regards,
Vladimir Marko
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (19 preceding siblings ...)
2004-12-20 17:09 ` SWElef at post dot sk
@ 2005-05-10 3:20 ` mmitchel at gcc dot gnu dot org
2005-05-10 5:55 ` pinskia at gcc dot gnu dot org
21 siblings, 0 replies; 23+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-05-10 3:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2005-05-10 03:19 -------
Fixed in 4.0; will not be fixed in 3.4.x.
--
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.4.4 |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Bug c++/17648] [3.3/3.4 Regression] template destructor was not called for inherited classes
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
` (20 preceding siblings ...)
2005-05-10 3:20 ` mmitchel at gcc dot gnu dot org
@ 2005-05-10 5:55 ` pinskia at gcc dot gnu dot org
21 siblings, 0 replies; 23+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-10 5:55 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-10 05:55 -------
(In reply to comment #18)
> Fixed in 4.0; will not be fixed in 3.4.x.
Closing as such then.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2005-05-10 5:55 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-24 8:10 [Bug c++/17648] New: template destrucktor was not called for inherited classes hs at profiforms dot de
2004-09-24 8:13 ` [Bug c++/17648] " hs at profiforms dot de
2004-09-24 8:14 ` hs at profiforms dot de
2004-09-24 9:08 ` [Bug c++/17648] template destructor " schwab at suse dot de
2004-09-24 11:50 ` pinskia at gcc dot gnu dot org
2004-09-24 12:43 ` bangerth at dealii dot org
2004-09-24 13:01 ` [Bug c++/17648] [3.3 regression] " bangerth at dealii dot org
2004-09-24 13:20 ` hs at profiforms dot de
2004-09-24 13:54 ` hs at profiforms dot de
2004-09-26 16:11 ` bangerth at dealii dot org
2004-09-27 3:26 ` giovannibajo at libero dot it
2004-09-27 14:29 ` gdr at cs dot tamu dot edu
2004-09-28 13:44 ` gdr at gcc dot gnu dot org
2004-10-06 15:01 ` hs at profiforms dot de
2004-10-28 3:49 ` [Bug c++/17648] [3.3/3.4 Regression] " giovannibajo at libero dot it
2004-10-28 3:54 ` pinskia at gcc dot gnu dot org
2004-10-28 15:30 ` reichelt at gcc dot gnu dot org
2004-10-28 16:33 ` giovannibajo at libero dot it
2004-11-01 0:14 ` mmitchel at gcc dot gnu dot org
2004-12-17 11:12 ` SWElef at post dot sk
2004-12-20 17:09 ` SWElef at post dot sk
2005-05-10 3:20 ` mmitchel at gcc dot gnu dot org
2005-05-10 5:55 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).