c – 在指向成员的指针声明中使用’decltype’有效吗?

想像一下这个奇怪的原因:
int main()
{
    struct S
    {        
        int i;
    } var;


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

GCC似乎编译很好,虽然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.

在这个定义中,我们感兴趣的是嵌套名称说明符,它在[expr.prim.general] / 8中定义为(强调我的):

nested-name-specifier:

::
type-name ::
namespace-name ::
decltype-specifier ::
nested-name-specifier identifier ::
nested-name-specifier templateopt simple-template-id ::

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...