【问题标题】:Where to place gcc function attribute in auto functiongcc 函数属性在 auto 函数中的位置
【发布时间】:2016-12-15 08:52:44
【问题描述】:

我正在尝试在具有尾随类型的自动函数上使用 gcc 函数属性,但 gcc 编译器一直拒绝该代码。我将 gcc 属性的位置基于此处的示例:

https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Function-Attributes.html

  // ok
  int my_int_gcc_func ()
  __attribute__(( abi_tag ("tag1") , weak )) //ok
  ;

  // error
  auto my_auto_gcc_func_not_working ()
  __attribute__(( abi_tag ("tag2") , weak )) // error
  -> int
  // cant place attribute here, get different warning..
  ;

参考文档将属性放在函数参数之后。

我通过反复试验注意到我可以将属性关键字移动到整个函数声明的前面,但找不到任何正式的规范说明 gcc 允许/支持这...

  // ok
  __attribute__(( abi_tag ("tag2") , weak )) // seems ok
  auto my_auto_gcc_func_no_error ()
  -> int
  ;

【问题讨论】:

    标签: c++ function gcc attributes auto


    【解决方案1】:

    似乎允许在函数声明前使用属性关键字。

    我在gcc属性语法spec中找到以下规则:

    一个属性说明符列表可能会出现在一个声明符之前(除了第一个),在一个声明符列表中,使用一个说明符和限定符列表来声明多个标识符。

    属性说明符列表可能紧接在逗号、= 或分号之前,以终止函数定义以外的标识符的声明。此类属性说明符适用于声明的对象或函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      相关资源
      最近更新 更多