This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/2320: incorrect order of destruction of function parameters



>Number:         2320
>Category:       c++
>Synopsis:       incorrect order of destruction of function parameters
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 19 09:16:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     James Kanze
>Release:        gcc version 2.95.2 19991024
>Organization:
>Environment:
Windows 2000, CygWin 1.1.8
>Description:
According to ISO 14882:1998, paragraph 6.6/2: "On exit from scope
(however accomplished), destructors are called for all constructed
objects with automatic storage duration (named objects or temporaries)
that are declared in that scope, in the REVERSE order of their
declaration."  You will note that the objects 3 and 4, above, are
destructed in the order of their declaration, not the reverse order.
>How-To-Repeat:
Compile function with:
    g++ --verbose orderdtors.cc -o order
Then execute program with
    order
Output is
A::A(): 1
B::B(): 2
A::A(A): 3
B::B(B): 4
A::~A(): 3
B::~B(): 4
B::~B(): 2
A::~A(): 1

The fourth and fifth lines should be inverted.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="orderdtors.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="orderdtors.cc"

DQojaW5jbHVkZSA8aW9zdHJlYW0uaD4NCg0KaW50IGluc3RhbmNlQ291bnQgPSAwIDsNCg0KY2xh
c3MgQSB7DQpwdWJsaWM6DQogICAgQSgpIDsNCiAgICBBKCBBIGNvbnN0JiApIDsNCiAgICB+QSgp
IDsNCnByaXZhdGU6DQogICAgaW50IGluc3RhbmNlIDsNCn0gOw0KDQpBOjpBKCkgOiBpbnN0YW5j
ZSggKytpbnN0YW5jZUNvdW50ICkgDQogICAgeyBjb3V0IDw8ICJBOjpBKCk6ICIgPDwgaW5zdGFu
Y2UgPDwgZW5kbCA7IH0NCkE6OkEoIEEgY29uc3QmICk6IGluc3RhbmNlKCArK2luc3RhbmNlQ291
bnQgKSAgDQogICAgeyBjb3V0IDw8ICJBOjpBKEEpOiAiIDw8IGluc3RhbmNlIDw8IGVuZGwgOyB9
DQpBOjp+QSgpIHsgY291dCA8PCAiQTo6fkEoKTogIiA8PCBpbnN0YW5jZSA8PCBlbmRsIDsgfQ0K
DQpjbGFzcyBCIHsNCnB1YmxpYzoNCiAgICBCKCkgOw0KICAgIEIoIEIgY29uc3QmICkgOw0KICAg
IH5CKCkgOw0KcHJpdmF0ZToNCiAgICBpbnQgaW5zdGFuY2UgOw0KfSA7DQoNCkI6OkIoKSA6IGlu
c3RhbmNlKCArK2luc3RhbmNlQ291bnQgKSANCiAgICB7IGNvdXQgPDwgIkI6OkIoKTogIiA8PCBp
bnN0YW5jZSA8PCBlbmRsIDsgfQ0KQjo6QiggQiBjb25zdCYgKTogaW5zdGFuY2UoICsraW5zdGFu
Y2VDb3VudCApICANCiAgICB7IGNvdXQgPDwgIkI6OkIoQik6ICIgPDwgaW5zdGFuY2UgPDwgZW5k
bCA7IH0NCkI6On5CKCkgeyBjb3V0IDw8ICJCOjp+QigpOiAiIDw8IGluc3RhbmNlIDw8IGVuZGwg
OyB9DQoNCg0Kdm9pZA0KZiggQSBhICwgQiBiICkNCnsNCn0NCg0KaW50DQptYWluKCkNCnsNCiAg
ICBBIGFuQSA7DQogICAgQiBhQiA7DQogICAgZiggYW5BICwgYUIgKSA7DQogICAgcmV0dXJuIDAg
Ow0KfQ0K


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]