2016-12-15 26 views
0

我想在尾隨類型的自動函數上使用gcc函數屬性,但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 
    ; 

回答

0

似乎允許在函數聲明前使用attribute關鍵字。

的屬性說明符列表可以立即出現在以逗號分隔的說明符的列表中的聲明的聲明符(比所述第一其他)之前:

以下規則我在gcc屬性語法spec發現多個標識符使用說明符和限定符的單個列表。

的屬性說明符列表可能會立即出現在逗號之前,=或分號終止比函數定義其它的標識符的聲明。這些屬性說明符適用於聲明的對象或函數。