Topic: Literals are rvalues, right?


Author: CornedBee <wasti.redl@gmx.net>
Date: Sat, 21 Aug 2010 22:05:11 CST
Raw View
On Aug 19, 1:11 am, ThosRTanner <ttann...@bloomberg.net> wrote:
> A large number of people said this:
>
> > See N3092 - 5.1.1 [expr.prim.general] /1:
>
> > "A string literal is an lvalue; all other literals are prvalues."
>
> Could someone explain that please? I'm having all sorts of problems
> getting my head round the concept of a literal that can be assigned to.

"Can be assigned to" is not a good explanation for an lvalue, and is
wrong in the standard's view of string literals, since they have a
const type. "Has a location" is a better one, and string literals need
a location (you usually deal with strings by having a pointer to the
memory location holding the characters), so the standard specifies
that they have one.

Sebastian


--
[ 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: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Wed, 11 Aug 2010 22:49:50 CST
Raw View
On 10 Aug., 21:28, Scott Meyers <NeverR...@aristeia.com> wrote:
> I must be blind, because I can't find anything in draft C++0x telling
> me that literals in general are rvalues.  2.13.6 tells me that boolean
> literals are rvalues, and 2.14.7 tells me that nullptr is an rvalue,
> but I don't see anything in 2.14.2 that tells me that integer literals
> are rvalues or in 2.14.5 that tells me that string literals are
> rvalues.  Nor can I find anywhere that tells me that enumerators are
> rvalues.
>
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?

They are prvalues, see 3.10/12 bullets 4+5:

    An rvalue (so called, historically, because rvalues could appear on
the
right-hand side of an assignment expressions) is an xvalue, a
temporary
object (12.2) or subobject thereof, or a value that is not associated
with
an object.

    A prvalue (   pure    rvalue) is an rvalue that is not an xvalue.
[ Example:
The result of calling a function whose return type is not a reference
is a
prvalue. The value of a literal such as 12, 7.3e5, or true is also a
prvalue.
   end example ]

HTH & Greetings from Bremen,

Daniel Kr   gler


--
[ 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: Stefan van Kessel <stefan.van.kessel@mytum.de>
Date: Wed, 11 Aug 2010 22:49:43 CST
Raw View
On 8/10/2010 9:28 PM, Scott Meyers wrote:
>
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?


"A prvalue (   pure    rvalue) is an rvalue that is not an xvalue. [
Example: The result of calling a function whose return type is not a
reference is a prvalue. The value of a literal such as 12, 7.3e5, or
true is also a prvalue.    end example ]" (3.10/1)


--
[ 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: Gennaro Prota <gennaro.prota@yahoo.com>
Date: Wed, 11 Aug 2010 22:49:20 CST
Raw View
On 10/08/2010 21.28, Scott Meyers wrote:
      [...]
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?

In the FCD, see 5.1.1p1. In C++03, see 5.1p2.

--
 Gennaro Prota         |           name.surname yahoo.com
   Breeze C++ (preview): <https://sourceforge.net/projects/breeze/>
   Do you need expertise in C++?   I'm available.

[ 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: CornedBee <wasti.redl@gmx.net>
Date: Wed, 11 Aug 2010 22:54:44 CST
Raw View
On Aug 10, 12:28 pm, Scott Meyers <NeverR...@aristeia.com> wrote:
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?

5.1.1p1: "A string literal is an lvalue; all other literals are
prvalues."

Sebastian


--
[ 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: Jerry Coffin <jerryvcoffin@yahoo.com>
Date: Wed, 11 Aug 2010 23:06:31 CST
Raw View
In article <i3pr8e$hi9$1@news.albasani.net>, NeverRead@aristeia.com
says...

[ ... ]

> Can somebody please point me to where the FCD tells me that
> literals are rvalues (or, if I'm mistaken, that they're lvalues)?

N3092,    5.1.1/1: "A string literal is an lvalue; all other
literals are prvalues."

--
   Later,
   Jerry.


[ 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: Howard Hinnant <howard.hinnant@gmail.com>
Date: Wed, 11 Aug 2010 23:01:13 CST
Raw View
On Aug 10, 3:28 pm, Scott Meyers <NeverR...@aristeia.com> wrote:
> I must be blind, because I can't find anything in draft C++0x telling
> me that literals in general are rvalues.  2.13.6 tells me that boolean
> literals are rvalues, and 2.14.7 tells me that nullptr is an rvalue,
> but I don't see anything in 2.14.2 that tells me that integer literals
> are rvalues or in 2.14.5 that tells me that string literals are
> rvalues.  Nor can I find anywhere that tells me that enumerators are
> rvalues.
>
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?

[expr.prim.general]/1:

> 1 A literal is a primary expression. Its type depends on its form (2.14).
> A string literal is an lvalue; all other literals are prvalues.

-Howard


--
[ 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: Wed, 11 Aug 2010 23:14:59 CST
Raw View
Scott Meyers wrote:

> I must be blind, because I can't find anything in draft C++0x telling
> me that literals in general are rvalues.  2.13.6 tells me that boolean
> literals are rvalues, and 2.14.7 tells me that nullptr is an rvalue,
> but I don't see anything in 2.14.2 that tells me that integer literals
> are rvalues or in 2.14.5 that tells me that string literals are
> rvalues.  Nor can I find anywhere that tells me that enumerators are
> rvalues.
>
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?
>

5.1.1/1: String literals are lvalues, all others are prvalues.


--
[ 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: Tue, 17 Aug 2010 14:12:56 CST
Raw View
On 10 =D0=B0=D0=B2=D0=B3, 23:28, Scott Meyers <NeverR...@aristeia.com> wrot=
e:
> Can somebody please point me to where the FCD tells me that literals
> are rvalues (or, if I'm mistaken, that they're lvalues)?

See N3092 - 5.1.1 [expr.prim.general] /1:

"A string literal is an lvalue; all other literals are prvalues."


--
[ 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<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: ThosRTanner <ttanner2@bloomberg.net>
Date: Thu, 19 Aug 2010 02:11:20 CST
Raw View
A large number of people said this:

> See N3092 - 5.1.1 [expr.prim.general] /1:
>
> "A string literal is an lvalue; all other literals are prvalues."
>

Could someone explain that please? I'm having all sorts of problems
getting my head round the concept of a literal that can be assigned to.

--
[ 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: Scott Meyers <NeverRead@aristeia.com>
Date: Tue, 10 Aug 2010 13:28:59 CST
Raw View
I must be blind, because I can't find anything in draft C++0x telling
me that literals in general are rvalues.  2.13.6 tells me that boolean
literals are rvalues, and 2.14.7 tells me that nullptr is an rvalue,
but I don't see anything in 2.14.2 that tells me that integer literals
are rvalues or in 2.14.5 that tells me that string literals are
rvalues.  Nor can I find anywhere that tells me that enumerators are
rvalues.

Can somebody please point me to where the FCD tells me that literals
are rvalues (or, if I'm mistaken, that they're lvalues)?

Thanks,

Scott

--
* C++ and Beyond: Meyers, Sutter, & Alexandrescu, Oct. 24-27 near
Seattle (http://cppandbeyond.com/)
* License my training materials for commercial
(http://tinyurl.com/yfzvkp9) or personal use
(http://tinyurl.com/yl5ka5p).

[ 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                      ]