public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: shaoben zhu <zhushaoben@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: A problem about g++ 4.8.5
Date: Thu, 28 Mar 2024 10:51:21 +0000	[thread overview]
Message-ID: <CAH6eHdQUtSVoftrZOio-0B_gQfMSNgED2Tt8tQp3j7q+M1Dj+Q@mail.gmail.com> (raw)
In-Reply-To: <CAH+YW_5VZnUXo5A8yzRN8AbYpHYo_7mrxaMMyEXd-sos1FtMEA@mail.gmail.com>

Hello,
This mailing list is for discussion the development of GCC itself.
Please use the gcc-help mailing list for help questions. Please send
any replies to that list instead of this one, thanks.

On Thu, 28 Mar 2024 at 09:35, shaoben zhu via Gcc <gcc@gcc.gnu.org> wrote:
>
> I compile my program using g++ 4.8.5, I find that when my program exits, it

That version is ancient and has not been supported by the GCC project
for many years. You might be able to get support for it from a vendor
who provided you with that version.

> first deconstructs the static member variables of class A, and then
> deconstructs a global object of class A. This caused an error in my program.
> Could you tell me how can I avoid this problem?Upgrade compiler
> version?Modify my code?
>
> my code like this:
> class A{
> static int var;
> ~A();                       //A  Destructor depended var
> };
>
> int A::var;
> A       obj;
>
> var deconstructs before obj

That's not what I see using g++ 4.8.5 on CentOS 6. With the following code:

struct M { ~M() { __builtin_puts("~M"); } };
struct A{
static M var;
~A() { __builtin_puts("~A"); }
};

M A::var;
A       obj;

int main()
{
}

I get this output:

~A
~M

N.B. I had to change your int to a class type, because int has no
destructor anyway, so doesn't get destroyed. So your example does not
demonstrate the problem you're describing.

If the definitions of A::var and obj are in the same source file then
the destructors should be in the reverse order of their definitions.
If they are in separate source files, then their initialization order
is unspecified, and so the destruction order is also unspecified. If
you define them in the same file, it should work correctly.

      reply	other threads:[~2024-03-28 10:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28  9:34 shaoben zhu
2024-03-28 10:51 ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdQUtSVoftrZOio-0B_gQfMSNgED2Tt8tQp3j7q+M1Dj+Q@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=zhushaoben@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).