public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: austern@apple.com
To: gcc-gnats@gcc.gnu.org
Subject: c++/8041: Array to pointer conversion in cast expression
Date: Wed, 25 Sep 2002 11:26:00 -0000	[thread overview]
Message-ID: <20020925182450.13999.qmail@sources.redhat.com> (raw)


>Number:         8041
>Category:       c++
>Synopsis:       Array to pointer conversion in cast expression
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 25 11:26:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     austern@apple.com
>Release:        2.96 (Redhat), 3.1, 3.2, 3.3 TOT
>Organization:
>Environment:
Linux
>Description:
Consider the following file:
void foo() {
  typedef int (&AP)[2][2];
  int a[2][2];

#ifdef NEW_STYLE_CAST
  AP ap = static_cast<AP>(a);
#else
  AP ap = (AP) a;
#endif
}

With all of the versions I listed above: this code compiles without error if -DNEW_STYLE_CAST is on the command line, but omitting it yields this error message:
  ap.cc:8: cannot convert `int (*)[2]' to `int[2][2]' in converting

The reason for the error message is that the compiler is applying the array-to-pointer standard conversion, so the argument to the cast expression is of type int (*)[2], which can't be cast to type AP.

I believe the compiler is incorrect in applying that standard conversion for the old-style cast, and that the static_cast behavior is right.  (Obviously one of the two must be wrong.)

Here's an analysis from William Miller, posted on the committee reflector:
  5.2.9p2 says that "static_cast<T>(e)" is well-formed if the
  declaration "T t(e);" is, and the effect is the same as using
  "t".  In this case, if "int (&t)[2](a)" is well-formed, the
  static_cast is as well.  In other words, it depends on how
  "a" is declared, but it's not automatically an error.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-09-25 18:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-25 11:26 austern [this message]
2002-12-19 17:27 bangerth
2003-02-14 19:06 René Møller Fonseca

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=20020925182450.13999.qmail@sources.redhat.com \
    --to=austern@apple.com \
    --cc=gcc-gnats@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).