Topic: Can array-to-pointer conversion be applied to the left operand of the arrow operator?


Author: Nikolay Ivchenkov <tsoae@mail.ru>
Date: Fri, 8 Jan 2010 11:22:11 CST
Raw View
Is the following code well-formed?

     struct X { int m; };

     int main()
     {
         X arr[1];
         arr->m = 2;
     }

I can't find which standard conversion sequences are allowed on the
left operand of -> operator.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Sun, 10 Jan 2010 09:48:10 CST
Raw View
Nikolay Ivchenkov wrote:

> Is the following code well-formed?
>
>      struct X { int m; };
>
>      int main()
>      {
>          X arr[1];
>          arr->m = 2;
>      }
>
> I can't find which standard conversion sequences are allowed on the
> left operand of -> operator.
>

I could find that this is handled by 5[expr]p8. But this does not handle

   struct Y { X arr[1]; };
   Y().arr->m = 2;

Since "Y().arr" is an rvalue, the paragraph doesn't apply. I fired the issue
here:
http://groups.google.com/group/comp.std.c++/browse_thread/thread/a9c4c488c6133ebb

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Nikolay Ivchenkov <tsoae@mail.ru>
Date: Sun, 10 Jan 2010 14:31:25 CST
Raw View
On 10 Jan, 18:48, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
>
> I could find that this is handled by 5[expr]p8.

This wording:

"Whenever an lvalue expression appears as an operand of an operator
that expects an rvalue for that operand, the lvalue-to-rvalue (4.1),
array-to-pointer (4.2), or function-to-pointer (4.3) standard
conversions are applied to convert the expression to an rvalue."

is too imprecise. What does "expected" mean here? And shall this
"whenever" be applied, for example, to all operands of comma or
conditional operator? Or "whenever" means "almost whenever" ("unless
otherwise specified")? :-)

> But this does not handle
>
>    struct Y { X arr[1]; };
>    Y().arr->m = 2;
>
> Since "Y().arr" is an rvalue, the paragraph doesn't apply.

Yes. I think, there shall be more precise rule.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]