In the following...
struct C {};
constexpr C c;
void g(C);
template<typename T>
void f(T&& t) {
g(std::forward<T>(t));
}
int main() {
f(c);
}
Is c
odr-used? Why / why not?
Going through the same motions as in Richard's answer, we find that the second condition for not being odr-used is violated, and thus c
is odr-used. In detail, the condition reads:
[A variable
x
is odr-used by an expressionex
unlessx
is an object and]ex
is an element of the set of potential results of an expressione
, where either the lvalue-to-rvalue conversion is applied toe
, ore
is a discarded-value expression.
In our case x
from the Standard is your c
, and ex
is the id-expression c
. The only expressions of which ex
is a potential result is the id-expression ex
itself. It is neither a discarded-value expression, nor is the lvalue-to-rvalue conversion applied to it (since it binds to a reference).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With