In C++11, how do I specify that the implicit “this” parameter “[[carries_dependency]]”?

c++11 attributes (1)

In [dcl.attr.depend]/1, I read:

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.

What I'm missing is a way to apply the attribute to the implicit this parameter.

By way of example, consider this free function:

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

and it's equivalent (but for the attribute) member version:

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

Answer #1

I'm not certain and don't have a compiler with support for this to test, but here's a swing at a possibility: I think the grammar [gram.decl] indicates that you should be able put it ("attribute-specifier_opt") in the same spot you'd put "const" to indicate a constant this pointer ("cv-qualifier-seq_opt"), which would make sense:

    ( parameter-declaration-clause ) attribute-specifier_opt cv-qualifier-seq_opt
        ref-qualifier_opt exception-specification_opt


struct X{
    void f(int i) [[carries_dependency]];