Odr using constexpr forwarded argument?

In the next ...

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?

+5
source share
1 answer

Going through the same movements as in Richard's answer , we find that the second condition for not using odr is violated, and therefore c is odr-used. In detail, the condition reads:

[A variable x is an odr-used expression ex , unless x is an object, and] ex is an element of the set of potential results of an expression e , where either the lvalue-to-rvalue transform is applied to e , or e is the discarded value.

In our case, x from the Standard specifies your c , and ex is the id-expression of c . The only expressions that ex is a potential result identifier is itself ex . It is not an expression of a discarded value and does not apply the lvalue-to-rvalue transformation (since it is bound to a link).

+4
source

Source: https://habr.com/ru/post/1210688/


All Articles