int main()
{
struct S
{
int i;
} var;
int decltype(var)::* pint = &decltype(var)::i;
}
GCC似乎编译很好,虽然Clang失败了一些不确定的语法相关的错误信息.
那么圣洁的ISO文件对此有什么看法 – 这是否有效?
解决方法
代码有效.
N4140 [dcl.mptr] / 1:
In a declaration
T DwhereDhas the formnested-name-specifier
*attribute-specifier-seqopt cv-qualifier-seqoptD1and the nested-name-specifier denotes a class,and the type of the identifier in the declaration
T D1is “derived-declarator-type-listT”,then the type of the identifier ofDis “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中定义为(强调我的):
nested-name-specifier:
::
type-name::
namespace-name::
decltype-specifier::
nested-name-specifier identifier::
nested-name-specifiertemplateopt simple-template-id::