代码之家  ›  专栏  ›  技术社区  ›  Vittorio Romeo

`friend`成员函数和属性-gcc vs clang

  •  4
  • Vittorio Romeo  · 技术社区  · 7 年前

    以下代码段:

    struct a
    {
        [[nodiscard]] friend int b();
    };
    

    在上编译时产生此错误 clang++ (trunk 342102) 具有 -std=c++17

    <source>:3:5: error: an attribute list cannot appear here
        [[nodiscard]] friend int b();
        ^~~~~~~~~~~~~
    

    friend 或是加入身体 b 防止错误。

    g++ (trunk) 很好地编译了代码。

    https://gcc.godbolt.org/z/ttTDuZ


    • clang++ 缺陷 ? 或者标准中是否有一些规则使得代码格式错误?

    • 叮当声++ 是正确的,什么是正确的方式标记 朋友 成员函数为 [[nodiscard]] ?

    1 回复  |  直到 7 年前
        1
  •  11
  •   NathanOliver    7 年前

    [dcl.attr.grammar]/5

    每个 属性说明符seq 属性说明符seq 属性 对齐说明符 如果 属于朋友声明的,该声明应为定义。 属性说明符seq

    重点矿山

    推荐文章