int main() { struct S { int i; } var; int decltype(var)::* pint = &decltype(var)::i; }
GCC似乎编译很好,虽然Clang失败了一些不确定的语法相关的错误信息.
那么圣洁的ISO文件对此有什么看法 – 这是否有效?
@H_502_8@解决方法
代码有效.
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.
在这个定义中,我们感兴趣的是嵌套名称说明符,它在[expr.prim.general] / 8中定义为(强调我的):
@H_502_8@ @H_502_8@ 原文链接:https://www.f2er.com/c/116097.htmlnested-name-specifier:
::
type-name::
namespace-name::
decltype-specifier::
nested-name-specifier identifier::
nested-name-specifiertemplate
opt simple-template-id::