public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8041: Array to pointer conversion in cast expression
@ 2003-02-14 19:06 René Møller Fonseca
0 siblings, 0 replies; 3+ messages in thread
From: René Møller Fonseca @ 2003-02-14 19:06 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/8041; it has been noted by GNATS.
From: =?ISO-8859-1?Q?Ren=E9_M=F8ller_Fonseca?= <fonseca@mip.sdu.dk>
To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org,
gcc-prs@gcc.gnu.org, austern@apple.com
Cc:
Subject: Re: c++/8041: Array to pointer conversion in cast expression
Date: Fri, 14 Feb 2003 19:58:47 +0100
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8041
This "implicit casting" problem seems to be related (checked with GCC 3.2 under GNU/Linux and Solaris).
#include <iostream>
using namespace std;
class MyClass {
public:
template<size_t SIZE>
MyClass(const int (&x)[SIZE]) throw() {
cout << "int[" << SIZE << "]" << endl;
}
template<size_t SIZE>
MyClass(long (&x)[SIZE]) throw() {
cout << "long[" << SIZE << "]" << endl;
}
};
MyClass myIntFunction() throw() {
static const int INT_ARRAY[999] = {}; // const
return INT_ARRAY; // this fails to compile
// GCC ERROR: conversion from `const int*' to non-scalar type `MyClass'
}
MyClass myLongFunction() throw() {
static long LONG_ARRAY[1234] = {}; // mutable
return LONG_ARRAY; // this fails to compile
// GCC ERROR: conversion from `long int*' to non-scalar type `MyClass'
}
int main() {
static const int INT_ARRAY[123] = {};
MyClass a(INT_ARRAY); // this works
MyClass b = INT_ARRAY; // this works
myIntFunction();
myLongFunction();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++/8041: Array to pointer conversion in cast expression
@ 2002-12-19 17:27 bangerth
0 siblings, 0 replies; 3+ messages in thread
From: bangerth @ 2002-12-19 17:27 UTC (permalink / raw)
To: austern, gcc-bugs, gcc-prs, nobody
Synopsis: Array to pointer conversion in cast expression
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Thu Dec 19 17:27:01 2002
State-Changed-Why:
Confirmed.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8041
^ permalink raw reply [flat|nested] 3+ messages in thread
* c++/8041: Array to pointer conversion in cast expression
@ 2002-09-25 11:26 austern
0 siblings, 0 replies; 3+ messages in thread
From: austern @ 2002-09-25 11:26 UTC (permalink / raw)
To: gcc-gnats
>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:
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-02-14 19:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-14 19:06 c++/8041: Array to pointer conversion in cast expression René Møller Fonseca
-- strict thread matches above, loose matches on Subject: below --
2002-12-19 17:27 bangerth
2002-09-25 11:26 austern
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).