在指向成员的指针声明中使用 'decltype' 是否有效?

Is using 'decltype' in the declaration of pointer to member valid?

想象一下,出于某种奇怪的原因,我写下了这个:

int main()
{
    struct S
    {        
        int i;
    } var;


    int decltype(var)::* pint = &decltype(var)::i;
}

GCC seems to compile it fine although Clang 失败并出现一些不确定的语法相关错误消息。

那么神圣的 ISO 文件对此有何评论 - 这是否有效?

这实际上是 Clang 中的 known bug

代码有效。

N4140 [dcl.mptr]/1:

In a declaration T D where D has the form

nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt D1

and the nested-name-specifier denotes a class, and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T”, then the type of the identifier of D is “derived-declarator-type-list cv-qualifier-seq pointer to member of class nested-name-specifier of type T”. 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-specifier templateopt simple-template-id ::