public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Matt Austern <austern@apple.com>
To: gcc@gcc.gnu.org
Subject: Address of a cast expression in C++
Date: Thu, 25 Jul 2002 13:47:00 -0000	[thread overview]
Message-ID: <77823DB0-9FFB-11D6-AF26-00039390D9E0@apple.com> (raw)

With both 3.1 and TOT, the following program is rejected by
the C front end but accepted by the C++ front end.  g++
compiles it without error or warning.
     #include <stdio.h>

     int main() {
       int n = 0;
       char* p = &(char)n;
      *p = 0x7f;
       printf("%x\n", n);
     }

As I read the C++ Standard, this is incorrect; a diagnostic is
required.  5.4/1 says that the result of (char)n is an rvalue,
and 5.3.1/2 says that you can't take the address of an rvalue.

Question: is this violation of the C++ Standard deliberate,
or is it a bug?

The reason I ask, of course, is that gcc has a generalized
lvalue extension.  The manual says that even with this
extension it's illegal to write &(int)f.  Who's wrong: the manual,
or the compiler?

			--Matt

             reply	other threads:[~2002-07-25 18:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-25 13:47 Matt Austern [this message]
2002-07-25 14:30 ` Gabriel Dos Reis
2002-08-06 16:27   ` Matt Austern
2002-08-06 16:37     ` Gabriel Dos Reis

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=77823DB0-9FFB-11D6-AF26-00039390D9E0@apple.com \
    --to=austern@apple.com \
    --cc=gcc@gcc.gnu.org \
    /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).