c++ - 在自动函数中放置 gcc 函数属性的位置

标签 c++ function gcc attributes auto

我试图在具有尾随类型的自动函数上使用 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
  ;

最佳答案

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

我在gcc属性语法中发现的以下规则spec :

An attribute specifier list may appear immediately before a declarator (other than the first) in a comma-separated list of declarators in a declaration of more than one identifier using a single list of specifiers and qualifiers.

An attribute specifier list may appear immediately before the comma, = or semicolon terminating the declaration of an identifier other than a function definition. Such attribute specifiers apply to the declared object or function.

关于c++ - 在自动函数中放置 gcc 函数属性的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41159934/

相关文章:

c++ - 在 Qt 信号中发出 QVector 引用会导致复制

c++ - c# 程序员尝试在 c++ 中处理事件

function - "chain"将加法运算符转换为接受 3 个参数的函数?

r - 使 Spark 函数可以从 mutate 中的定制函数中访问

c - 从 fgets() 输入中删除尾随换行符

c++ - 这些 GCC/G++ 参数是什么?

c++ - 通过 Post 数据接收到的 Un-Escape 字符串

c++ - 需要在 C++ 中初始化的持久全局数据

javascript - 函数循环的可能解决方案

gcc - C程序编译错误