Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.3 中 原始字面量不一定是右值 #102

Closed
cathaysia opened this issue May 31, 2020 · 2 comments · Fixed by #105
Closed

3.3 中 原始字面量不一定是右值 #102

cathaysia opened this issue May 31, 2020 · 2 comments · Fixed by #105
Labels

Comments

@cathaysia
Copy link
Contributor

实际描述

  • 文件路径:例如,book/zh-cn/03-runtime.md
  • 原文段落:
运算表达式产生的临时变量、 原始字面量、Lambda 表达式都属于纯右值。

原文表意不准确:

原始字面量并不一定是右值,比如 字符字面量,字符字面量可以被取地址,是一个左值。

参见:https://en.cppreference.com/w/cpp/language/value_category

@cathaysia
Copy link
Contributor Author

cathaysia commented May 31, 2020

更加糟糕的是,在类中的字符字面量是一个右值:

class Parent{
const char* s = &"hello"; // 此时 "hello" 为右值,无法取地址,无法通过编译
}

int main(){
    &“hello”; // 此时"hello"为左值,可以去地址,可以通过编译
}

@changkun
Copy link
Owner

PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants