public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mike Stump <mrs@windriver.com>
To: mark@codesourcery.com, per@bothner.com
Cc: gcc@gcc.gnu.org
Subject: Re: GCC's statement expression extension
Date: Tue, 01 Aug 2000 18:14:00 -0000	[thread overview]
Message-ID: <200008020114.SAA09384@kankakee.wrs.com> (raw)

> To: per@bothner.com
> From: Mark Mitchell <mark@codesourcery.com>
> Date: Sat, 29 Jul 2000 10:42:58 -0700

> That seems like the obvious right answer.  It just doesn't work very
> well for:

>   X x;
>   X f();

>   x = ({ f(); });

It seems like it does to me.  There is a preexisting references extend
the life of temporaries rule already in the C++ standard that I think
covers one sensible way to treat this case.  With that, it make
perfect sense to me.  It is true, that we have to realize that rule
`fits' in this situation, I see that as obvious.

> Oops.  The return value of f() got destroyed before we got a chance to
> copy it.  (There are more complex examples with similar problems,
> including binding things to references, which cause lifetime
> extensions in C++.)

It seems like the same issue to me.

> To: Mark Mitchell <mark@codesourcery.com>
> From: Alexandre Oliva <aoliva@redhat.com>
> Date: 29 Jul 2000 15:47:26 -0300

> I see.  We'd have to have copied it to some temporary that would
> hold the result of the statement expression before calling its
> destructor.

A copy ctor to another temporary is another way to think about this.
This also fits, though, at first blush I think less well than
extending the lifetime.  Though, there might be technical reasons that
cause one to want to mandate a copy, and then permit the compiler to
get it of it, if it can.

> To: Mark Mitchell <mark@codesourcery.com>
> From: Alexandre Oliva <aoliva@redhat.com>
> Date: 29 Jul 2000 16:29:53 -0300

> How about, for a start, mandating that the result of a statement
> expression be a POD object?  This would get us rid of the problem of
> handling destructors

I don't see a problem handling destructors.  I think the inside temps
expire at their full expression within the statements, and the object
that escapes from the expression in the expression statement has its
lifetime extended.  Simple, easy, consistent, predictable and in the
spirit of the standard.

> To: aoliva@redhat.com
> From: Mark Mitchell <mark@codesourcery.com>
> Date: Sat, 29 Jul 2000 12:52:41 -0700

> There are other problems too:

>   #define foo(X) ({ /* some code */ f(X); /* some more code */ })

> Now, suppose that X is an expression that creates temporaries, and
> that `foo' is a standard library function.  (I've seen this with the
> glibc headers by the way.  Some of them do something like:

>   #define foo(x) ({ int i = x; ... }) 

> which has this form.)

> Then, temporaries involved in the X expression are destroyed at the
> end of the statement-expression, which is earlier than the language
> says they should be.  We break conformant programs in this way.

I find the argument where a person misuses #defines and doesn't meet
the requirements of the standard and breaks conformant code this way,
while implementing parts of the standard, to be not very convincing.
They can misuse a good number of features to break user code already.

> That's another reason why this construct has such difficult semantics
> in C++.

I don't see it this way.

> To: Mark Mitchell <mark@codesourcery.com>
> From: Alexandre Oliva <aoliva@redhat.com>
> Date: 29 Jul 2000 18:07:12 -0300

> On Jul 29, 2000, Mark Mitchell <mark@codesourcery.com> wrote:

> > There's really no right answer -- the other answer is to wait
> > until the end of the enclosing full expression.

> It appears to me that this would solve all of the problems you've
> listed so far, and it seems reasonably sound to me.

I don't think it is reasonable.  The words in the standard say that
certainly by the time the statement containing an expression ends, the
temps are gone.  You cannot violate this rule without a very good
reason.

> To: aoliva@redhat.com
> From: Mark Mitchell <mark@codesourcery.com>
> Date: Sun, 30 Jul 2000 10:06:06 -0700

> You can define the semantics any weird way you want, and given N
> problems you can probably come up with a semantics that solves all N
> of them.  What I don't think possible, unfortunately, is come up
> with semantics that are consistent, in the spirit of C++, and easy
> for users to understand, and will solve the N+1st problem.

I disagree.  What problems remain?

> It adds no additional power, it provides no additional cleanliness,
> affords no portability.  On the other hand, it has dubious
> semantics, at best, and is difficult to implement (especially when
> you consider using these things in default arguments.

What are the issues you don't like with regard to default arguments?

             reply	other threads:[~2000-08-01 18:14 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-01 18:14 Mike Stump [this message]
2000-08-01 21:52 ` Mark Mitchell
2000-08-02 16:59 ` Alexandre Oliva
2000-08-02 21:01   ` Per Bothner
  -- strict thread matches above, loose matches on Subject: below --
2000-08-04  5:39 Mark Kettenis
2000-08-04  9:06 ` Mark Mitchell
2000-08-03 16:48 John Marshall
2000-08-03 16:55 ` Mark Mitchell
2000-08-03 14:32 Mike Stump
2000-08-04  4:36 ` Jamie Lokier
2000-08-04  9:04   ` Mark Mitchell
2000-08-04  9:26     ` Jamie Lokier
2000-08-04 13:19       ` Mark Mitchell
2000-08-02 13:44 Mike Stump
2000-08-03 10:55 ` Jamie Lokier
2000-08-03 16:13   ` Mark Mitchell
2000-08-04 12:38     ` Kamil Iskra
2000-08-04 13:24       ` Mark Mitchell
2000-08-05 11:56         ` Kamil Iskra
2000-08-05 12:03           ` Mark Mitchell
2000-07-31  9:31 Phil Edwards
2000-07-30  3:49 Richard Kenner
2000-07-28 13:08 Kaveh R. Ghazi
2000-07-28 13:45 ` Mark Mitchell
2000-07-28 12:14 Kaveh R. Ghazi
2000-07-28 12:22 ` Mark Mitchell
2000-07-28 12:01 Anjul Srivastava
2000-07-28 12:11 ` Gabriel Dos Reis
2000-07-28 13:33 ` sidster
2000-07-27 19:46 Richard Kenner
2000-07-27 21:11 ` Jim Wilson
2000-07-27 19:29 Richard Kenner
2000-07-27 19:39 ` Jeffrey A Law
2000-07-27 19:45   ` Michael Meissner
2000-07-27 20:16     ` Mark Mitchell
2000-07-27 20:50       ` Michael Meissner
2000-07-27 20:57         ` Jim Wilson
2000-07-27 21:25         ` Mark Mitchell
2000-07-27 20:14 ` Mark Mitchell
2000-07-27 19:20 Richard Kenner
2000-07-27 19:26 ` Mark Mitchell
2000-07-30 12:09   ` Linus Torvalds
2000-07-27 18:41 Richard Kenner
2000-07-27 19:15 ` Mark Mitchell
2000-07-28  3:59   ` Marc Espie
2000-07-28  8:11     ` Mark Mitchell
2000-08-02 15:00   ` Kamil Iskra
2000-08-02 15:14     ` Mo McKinlay
2000-08-02 15:18     ` Mark Mitchell
2000-07-27 18:24 Richard Kenner
2000-07-27 18:38 ` Mark Mitchell
2000-07-27 19:21   ` Michael Meissner
2000-07-27 21:15     ` Jim Wilson
2000-07-28  7:31       ` Michael Meissner
2000-07-28  9:08         ` Nick Ing-Simmons
2000-07-28  9:19           ` Gabriel Dos Reis
2000-07-28  9:37             ` Nick Ing-Simmons
2000-07-27 23:53   ` Gabriel Dos Reis
2000-07-28 12:08   ` Stan Shebs
2000-07-28 12:16     ` Gabriel Dos Reis
2000-07-28 13:07       ` Stan Shebs
2000-07-28 12:28     ` Mark Mitchell
2000-07-28 14:08       ` Stan Shebs
2000-07-28 17:49         ` llewelly
2000-07-28 22:54           ` Mark Mitchell
2000-07-28 22:40         ` Mark Mitchell
2000-07-29 10:28           ` Per Bothner
2000-07-29 10:43             ` Mark Mitchell
2000-07-29 11:48               ` Alexandre Oliva
2000-07-29 12:09                 ` Mark Mitchell
2000-07-29 12:30                   ` Alexandre Oliva
2000-07-29 12:52                     ` Mark Mitchell
2000-07-29 14:07                       ` Alexandre Oliva
2000-07-30 10:06                         ` Mark Mitchell
2000-07-30  9:29                   ` Per Bothner
2000-07-30 11:23                 ` Linus Torvalds
2000-07-29 18:00               ` Per Bothner
2000-07-29 16:20         ` Marc Espie
2000-07-21 16:31 Joseph S. Myers
2000-07-23  9:39 ` Jeffrey A Law
2000-07-23  9:52   ` Mark Mitchell
2000-07-24 15:48     ` Geoff Keating
2000-07-25  8:44       ` Mark Mitchell
2000-07-26 21:25       ` Richard Henderson
2000-07-26 21:24     ` Richard Henderson
2000-07-26 21:38       ` Mark Mitchell
2000-07-26 22:51         ` Linus Torvalds
2000-07-27 21:14           ` Marc Espie
2000-07-27 21:28             ` Mark Mitchell
2000-07-27 21:29             ` Mo McKinlay
2000-07-28  0:45               ` Akbar A.
2000-07-28  7:27               ` Michael Meissner
2000-07-28 11:50             ` Linus Torvalds
2000-07-28 21:14               ` Marc Espie
2000-07-28 21:28                 ` Linus Torvalds
2000-07-29  1:40                   ` Marc Espie
2000-07-30 10:21                     ` Linus Torvalds
2000-07-27  4:34         ` Joseph S. Myers
2000-07-27  4:53           ` Gabriel Dos Reis
2000-07-27  9:42           ` Mark Mitchell
2000-07-27 17:32             ` Michael Meissner
2000-07-27 14:51           ` Alexandre Oliva
2000-07-29 10:41         ` Per Bothner
2000-07-29 14:36           ` Jamie Lokier

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=200008020114.SAA09384@kankakee.wrs.com \
    --to=mrs@windriver.com \
    --cc=gcc@gcc.gnu.org \
    --cc=mark@codesourcery.com \
    --cc=per@bothner.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).