Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the value category of string literals?

Tags:

c++

c++11

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?

like image 407
Andrew Tomazos Avatar asked Feb 23 '13 02:02

Andrew Tomazos


1 Answers

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.

like image 62
Andy Prowl Avatar answered Oct 26 '22 16:10

Andy Prowl