Topic: Rvalue of array type?
Author: Eugene.Alterman@autodesk.com ("Eugene Alterman")
Date: Mon, 8 Dec 2003 23:20:11 +0000 (UTC) Raw View
'4.2 Array to pointer conversion' mentions lvalue or rvalue of array type.
What I don't understand is how an array type can be an rvalue.
Is there such a thing as an rvalue of array type?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Mon, 8 Dec 2003 23:44:34 +0000 (UTC) Raw View
In article <1070914559.362209@hqnntp01.autodesk.com>, Eugene Alterman
<Eugene.Alterman@autodesk.com> writes
>'4.2 Array to pointer conversion' mentions lvalue or rvalue of array type.
>What I don't understand is how an array type can be an rvalue.
>Is there such a thing as an rvalue of array type?
I am not sure but:
struct X {
int ar[10];
};
void foo (X t);
int main(){
X x ={0};
foo(x);
}
What is the type of x.ar in the call to foo()?
--
Francis Glassborow ACCU
If you are not using up-to-date virus protection you should not be reading
this. Viruses do not just hurt the infected but the whole community.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Eugene.Alterman@autodesk.com ("Eugene Alterman")
Date: Tue, 9 Dec 2003 04:12:00 +0000 (UTC) Raw View
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:Yc33xHDvxQ1$EwP0@robinton.demon.co.uk...
> In article <1070914559.362209@hqnntp01.autodesk.com>, Eugene Alterman
> <Eugene.Alterman@autodesk.com> writes
> >'4.2 Array to pointer conversion' mentions lvalue or rvalue of array
type.
> >What I don't understand is how an array type can be an rvalue.
> >Is there such a thing as an rvalue of array type?
>
>
> I am not sure but:
>
> struct X {
> int ar[10];
> };
>
> void foo (X t);
>
> int main(){
> X x ={0};
> foo(x);
> }
>
> What is the type of x.ar in the call to foo()?
int[10] :-)
Well, 5.2.5/4 states that "if E1 is an lvalue then E1.E2 is an lvalue".
But it does not say that otherwise it is an rvalue.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: rani_sharoni@hotmail.com ("Rani Sharoni")
Date: Tue, 9 Dec 2003 11:52:54 +0000 (UTC) Raw View
Francis Glassborow wrote:
> In article <1070914559.362209@hqnntp01.autodesk.com>, Eugene Alterman
> <Eugene.Alterman@autodesk.com> writes
>> '4.2 Array to pointer conversion' mentions lvalue or rvalue of array
>> type. What I don't understand is how an array type can be an rvalue.
>> Is there such a thing as an rvalue of array type?
>
>
> I am not sure but:
>
> struct X {
> int ar[10];
> };
>
> void foo (X t);
>
> What is the type of x.ar in the call to foo()?
In the spirit of the standard (C/C++) it's certainly an r-value. DR #421 by
Gabriel Dos Reis makes it clear:
Change the second bullet of 5.2.5 expr.ref paragraph 4 to read: If E1 is
an lvalue, then E1.E2 is an lvalue; *otherwise, it is an rvalue*.
Let's see what compilers think about it:
struct A { int X[1]; };
int main()
{
&A().X; //#1 ill-formed
int (&r)[1] = A().X; //#2 ill-formed
long* f(int (&)[1]); //#3
char* f(int const (&)[1]); //#4
// affect overload resolution
char* x = f(A().X); // #5 selects #4
}
EDG is consistent about A().X being an r-value.
GCC rejected #2 and #5 (no matching function)
VC is consistent about A().X being an l-value.
BCC is consistent about A().X being an l-value but didn't found match for #5
It's also interesting to check out the C behavior of those compliers:
/* warning code in C */
struct A { int X[10]; };
struct A f(void);
int main(void)
{
&f().X; // #6
return 0;
}
EDG and GCC rejected #6
BCC and VC accepted it.
For non-array types BCC and VC changed their mind and agreed that E1.E2 is
r-value (C/C++).
I guess that the root of the confusion is that there is no way to produce
array r-value directly (i.e. array return type of function).
Rani
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: Tue, 9 Dec 2003 11:53:23 +0000 (UTC) Raw View
On Mon, 8 Dec 2003 23:44:34 +0000 (UTC), francis@robinton.demon.co.uk
(Francis Glassborow) wrote:
> In article <1070914559.362209@hqnntp01.autodesk.com>, Eugene Alterman
> <Eugene.Alterman@autodesk.com> writes
> >'4.2 Array to pointer conversion' mentions lvalue or rvalue of array type.
> >What I don't understand is how an array type can be an rvalue.
> >Is there such a thing as an rvalue of array type?
> I am not sure but:
> struct X {
> int ar[10];
> };
> void foo (X t);
> int main(){
> X x ={0};
> foo(x);
> }
> What is the type of x.ar in the call to foo()?
I don't think that qualifies. The value parameter is initialized
by a copy of x and is an lvalue within foo. The copy ctor took an
X const&. I don't see any rvalue.
Try this amusing one.
struct S { int a[10]; };
S f () { return S(); }
int main () {
int* p = f().a;
assert("Poof!");
}
John
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: rani_sharoni@hotmail.com ("Rani Sharoni")
Date: Wed, 10 Dec 2003 03:42:03 +0000 (UTC) Raw View
"Eugene Alterman" wrote:
> '4.2 Array to pointer conversion' mentions lvalue or rvalue of array
> type. What I don't understand is how an array type can be an rvalue.
> Is there such a thing as an rvalue of array type?
4.2/1 says: An lvalue or rvalue of type "array of N T" or "array of unknown
bound of T" can be converted to an rvalue of type "pointer to T."
So the r-value mentioned in 4.2 is of pointer type and not array type.
As posted before array types r-values can't be produced directly but in
context in which the array is non-static member of type then in r-value
expression of that type it's, like any other non-reference types, an r-value
and DR #421 makes it clear.
struct A { int X[1]; };
A().X // r-value expression of array type (int[1]).
One consequence of this rule is that you can't bind the member to non const
reference which is consistent with the rest of the language.
Except for:
struct B {
void f();
void f() const;
};
B().f() // The r-value of type B (*this invisible parameter) is bounded to
B& - cheers!
Rani
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Eugene Alterman" <Eugene.Alterman@autodesk.com>
Date: Thu, 11 Dec 2003 00:53:11 CST Raw View
""Rani Sharoni"" <rani_sharoni@hotmail.com> wrote in message
news:3fd599fd@news.microsoft.com...
> In the spirit of the standard (C/C++) it's certainly an r-value. DR #421
by
> Gabriel Dos Reis makes it clear:
> Change the second bullet of 5.2.5 expr.ref paragraph 4 to read: If E1 is
> an lvalue, then E1.E2 is an lvalue; *otherwise, it is an rvalue*.
Even if E2 is a reference?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Eugene.Alterman@autodesk.com ("Eugene Alterman")
Date: Thu, 11 Dec 2003 22:17:45 +0000 (UTC) Raw View
"Eugene Alterman" <Eugene.Alterman@autodesk.com> wrote in message
news:WLJBb.4709$_Q6.4643@newssvr33.news.prodigy.com...
> ""Rani Sharoni"" <rani_sharoni@hotmail.com> wrote in message
> news:3fd599fd@news.microsoft.com...
> > In the spirit of the standard (C/C++) it's certainly an r-value. DR #421
> by
> > Gabriel Dos Reis makes it clear:
> > Change the second bullet of 5.2.5 expr.ref paragraph 4 to read: If E1
is
> > an lvalue, then E1.E2 is an lvalue; *otherwise, it is an rvalue*.
>
> Even if E2 is a reference?
Never mind.
If E2 is a reference then E1.E2 is an lvalue.
This case is covered by the first sentence of 5.2.5/4.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: rani_sharoni@hotmail.com ("Rani Sharoni")
Date: Fri, 12 Dec 2003 02:22:23 +0000 (UTC) Raw View
Eugene Alterman wrote:
> ""Rani Sharoni"" <rani_sharoni@hotmail.com> wrote in message
> news:3fd599fd@news.microsoft.com...
>> In the spirit of the standard (C/C++) it's certainly an r-value. DR
>> #421 by Gabriel Dos Reis makes it clear:
>> Change the second bullet of 5.2.5 expr.ref paragraph 4 to read: If
>> E1 is an lvalue, then E1.E2 is an lvalue; *otherwise, it is an
>> rvalue*.
>
> Even if E2 is a reference?
Obviously not!
Long 5.2.5/4 specifies the reference case in the beginning of the paragraph:
If E2 is declared to have type "*reference* to T", then E1.E2 is an
*lvalue*; the type of E1.E2 is T. Otherwise, one of the following rules
applies.
[...]
Rani
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]