21

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?
curiousguy
  • 8,038
  • 2
  • 40
  • 58
Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
  • 1
    I am quite sure that it can be done, but you will have to look the syntax in the standard. I can try to guess that it will be something like `[[carries_dependency]] void fun( int );` or `void fun(int) [[carries_dependency]];` in the declaration. – David Rodríguez - dribeas Jul 03 '12 at 17:20
  • 1
    @David Rodríguez - dribeas If I'm reading the grammar right the former applies the attribute to the return values of the function (if any) while the latter isn't allowed. – Mark B Jul 03 '12 at 17:28
  • @MarkB: 8.4.1p2 seems to indicate that the function attributes are to be the last elements in the function declaration. – David Rodríguez - dribeas Jul 03 '12 at 17:42
  • 11
    I'm curious: what compiler actually implements C++11's attribute syntax? – Nicol Bolas Jul 03 '12 at 18:59

1 Answers1

3

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:

parameters-and-qualifiers:
    ( parameter-declaration-clause ) attribute-specifier_opt cv-qualifier-seq_opt
        ref-qualifier_opt exception-specification_opt

E.g.

struct X{
    void f(int i) [[carries_dependency]];
};
Steve M
  • 8,246
  • 2
  • 25
  • 26