7

I'm pretty sure the value category of integer, character, boolean and floating point literals is prvalue.

User defined literals are like function calls, so their value category depends on the return type of the operator function they resolve to.

I'm not clear on string literals. They have type "array of const charx" where charx is some character type.

It says in 3.10:

The value of a literal ... is also a prvalue.

But I think this might not apply to string literals?

What is the value category of a string literal? How did you determine this?

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319

1 Answers1

16

So I'm pretty sure the value category of integer, character, boolean and floating literals are prvalues.

That's correct.

What is the value category of a string literal?

Per Paragraph 5.1.1/1 of the C++11 Standard:

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.

Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
  • 1
    That does not make sense to me. Why would a string literal be an lvalue and not a prvalue? – Remy Lebeau Feb 23 '13 at 02:28
  • 3
    @RemyLebeau: Because it is an object. You can, for example, take its address, something you cannot do with an integer or floating point literal. http://liveworkspace.org/code/UAvdz$3 – Benjamin Lindley Feb 23 '13 at 02:39
  • 3
    @RemyLebeau: Because it basically _must_ have storage. – Lightness Races in Orbit Feb 23 '13 at 14:33
  • Which part should we read to see the corresponding paragraph in C++20 Standard? I tried to see 5.1.1. and also tried to search the term but couldn't find it. P.S. @LightnessRacesinOrbit's comment nails the point IMO. – starriet Sep 30 '22 at 02:22