[英]In C++11, how do I specify that the implicit "this" parameter "[[carries_dependency]]"?
在[dcl.attr.depend]/1 中,我讀到:
屬性[...]
carries_dependency
[...] 可以應用於函數聲明或 lambda 中parameter-declaration
的declarator-id
,在這種情況下,它指定參數的初始化攜帶對 (1.10 ) 該對象的每個左值到右值轉換 (4.1)。 該屬性還可以應用於函數聲明的declarator-id
,在這種情況下,它指定返回值(如果有)攜帶對函數調用表達式求值的依賴性。
我缺少的是將屬性應用於隱式this
參數的方法。
舉例來說,考慮這個自由函數:
void fun(int i, Foo * [[carries_dependency]] f);
它是等效的(但對於屬性)成員版本:
void Foo::fun(int i); // can't add [[carries_dependency]] here?
我不確定並且沒有支持此測試的編譯器,但是這里有一個可能性:我認為語法 [gram.decl] 表明您應該可以將它(“attribute-specifier_opt” ) 在您將“const”置於指示常量 this 指針(“cv-qualifier-seq_opt”)的同一位置,這很有意義:
parameters-and-qualifiers:
( parameter-declaration-clause ) attribute-specifier_opt cv-qualifier-seq_opt
ref-qualifier_opt exception-specification_opt
例如
struct X{
void f(int i) [[carries_dependency]];
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.