想象一下,出于某种奇怪的原因,我写下了这个:
int main()
{
struct S
{
int i;
} var;
int decltype(var)::* pint = &decltype(var)::i;
}
GCC尽管 Clang 似乎编译得很好失败并出现一些不确定的语法相关错误消息。
那么神圣的 ISO 文件对此有何评论 - 这是否有效?
最佳答案
这实际上是一个known bug在 Clang 中。
代码有效。
N4140 [dcl.mptr]/1:
In a declaration
T D
whereD
has the formnested-name-specifier
*
attribute-specifier-seqopt cv-qualifier-seqoptD1
and the nested-name-specifier denotes a class, and the type of the identifier in the declaration
T D1
is “derived-declarator-type-listT
”, then the type of the identifier ofD
is “derived-declarator-type-list cv-qualifier-seq pointer to member of class nested-name-specifier of typeT
”. The optional attribute-specifier-seq (7.6.1) appertains to the pointer-to-member.
在这个定义中,我们对nested-name-specifier 感兴趣,它在 [expr.prim.general]/8 中定义为(强调我的):
nested-name-specifier:
::
type-name::
namespace-name::
decltype-specifier::
nested-name-specifier identifier::
nested-name-specifiertemplate
opt simple-template-id::
关于c++ - 在指向成员的指针声明中使用 'decltype' 是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31206462/