gpt4 book ai didi

c++ - 除标识符外,非限定标识符如何根据左值和右值进行分类?

转载 作者:太空狗 更新时间:2023-10-29 23:14:51 25 4
gpt4 key购买 nike

似乎标准并没有明确讲到一些unqualified-id的表达类别。另一方面,作为 unqualified-id 之一的 identifier 分类如下:

The result is an lvalue if the entity is a function, variable, or data member and a prvalue otherwise.

那么,其他unqualified-id呢——operator-function-id, conversion-function-id, literal -operator-id, ~class-name, ~decltype-specifier, template-id?

最佳答案

这已被确认为 Core Working Group issue 536几乎是 10 年前提交的。所以可能它还没有被认为重要到需要修复。

More importantly, some kinds of id-expressions are not described by 5.1.1 [expr.prim.general]. The structure of this section is that the result, type, and lvalue-ness are specified for each of the cases it covers [...]

This treatment leaves unspecified all the non-identifier unqualified-ids (operator-function-id, conversion-function-id, and template-id) [...]

-- CWG 536


从各种编译器的行为来看,我们可以假设其意图是所有这些表达式都遵循标识符规则:

The type of the expression is the type of the identifier. The result is the entity denoted by the identifier. The result is an lvalue if the entity is a function, variable, or data member and a prvalue otherwise.

-- post-N4296 [expr.prim.general]p13

顺便说一句:除了template-id 之外的所有这些表达式都只能引用函数。 Template-id 也可以引用变量。 template-id和普通的identifier都可以引用类和枚举,这让我有点困惑(可以有int这样的表达式吗?它们是纯右值吗?)

关于c++ - 除标识符外,非限定标识符如何根据左值和右值进行分类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31761091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com