gpt4 book ai didi

c++ - 在 C++11 中,如何指定隐式 "this"参数 "[[carries_dependency]]"?

转载 作者:IT老高 更新时间:2023-10-28 21:48:20 24 4
gpt4 key购买 nike

[dcl.attr.depend]/1 中,我读到:

The attribute[...] carries_dependency [...] may be applied to the declarator-id of a parameter-declaration in a function declaration or lambda, in which case it specifies that the initialization of the parameter carries a dependency to (1.10) each lvalue-to-rvalue conversion (4.1) of that object. The attribute may also be applied to the declarator-id of a function declaration, in which case it specifies that the return value, if any, carries a dependency to the evaluation of the function call expression.

我缺少的是一种将属性应用于隐式 this 参数的方法。

例如,考虑这个自由函数:

void fun(int i, Foo * [[carries_dependency]] f);

它是等效的(但对于属性)成员版本:

void Foo::fun(int i); // can't add [[carries_dependency]] here?

最佳答案

我不确定并且没有支持此测试的编译器,但这里有一个可能性:我认为语法 [gram.decl] 表明您应该能够把它(“属性-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]];
};

关于c++ - 在 C++11 中,如何指定隐式 "this"参数 "[[carries_dependency]]"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11314580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com