Carries_dependency is a C++11 Generalized Attribute that can be applied to function parameters and the function return value. Applied to a function parameter, it tells the compiler that a data dependency may be carried into the function through that parameter. Applied to the return value, it tells the compiler that the function return value carries a data dependency out of the function. This might allow the compiler to drop memory fences otherwise needed.
Questions tagged [carries-dependency]
7 questions
81
votes
2 answers
What does the [[carries_dependency]] attribute mean?
Can someone explain it in a language that mere mortals understand?

Yakov Galka
- 70,775
- 16
- 139
- 220
21
votes
1 answer
In C++11, how do I specify that the implicit "this" parameter "[[carries_dependency]]"?
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…

Marc Mutz - mmutz
- 24,485
- 12
- 80
- 90
5
votes
1 answer
Why isn't [[carries_dependency]] the default in C++?
I know that memory_order_consume has been deprecated, but I'm trying to understand the logic that went into the original design and how [[carries_dependency]] and kill_dependency were supposed to work. For that, I would like a specific example of…

user3188445
- 4,062
- 16
- 26
5
votes
2 answers
When should you not use [[carries_dependency]]?
I've found questions (like this one) asking what [[carries_dependency]] does, and that's not what I'm asking here.
I want to know when you shouldn't use it, because the answers I've read all make it sound like you can plaster this code everywhere…

Matthew Reddington
- 1,409
- 3
- 13
- 24
4
votes
1 answer
Why do left operands of logical AND/OR not carry dependency to the parent evaluation?
According to C++ standards:
An evaluation A carries a dependency to an evaluation B if - the value of A is used as an operand of B, unless:
— B is an invocation of any specialization of std::kill_dependency (29.3), or
— A is the left operand of a…

Lifu Huang
- 11,930
- 14
- 55
- 77
4
votes
1 answer
[[carries_dependency]] what it means and how to implement
I was reading about [[carries_dependency]] in this SO post.
But what I could not understand is the below sentences in the accepted answer :
"In particular, if a value read with memory_order_consume is passed in
to a function, then without…

Programmer
- 8,303
- 23
- 78
- 162
0
votes
0 answers
Mfence would be inserted by compiler to function using non atomic pointer storing value of atomic pointer
I am reading cppreference of carries_dependency attribute.
It seems to me that the following codes snippet from above link is telling that if carries_dependency attribute is not added to print2 function, because of passing the non-atomic pointer…

cpp
- 265
- 1
- 6