mercredi 1 mars 2017

Continuation of "I just can not understand DR 172"

This is basically a continuation of my prior question about DR 172. Let me first explain why I'm insisting in looking at something that could be considered old, as the C++11 Standard, but my problem is that the section [basic.def.odr] is already difficult to understand in C++11, and I want to cover this completely before I delve into the same section in the current draft, which in my opinion, is even more complicated.

The answer to my prior question by Austing Hastings was great, but I still have one little point that is not clear in [basic.def.odr]/2 in C++11. Consider this little and very simple example:

const int i = 1;
int main()
{
    int j = i;
}

From [basic.def.odr]/2 in C++11 i is not odr-used in int j = i; as i is an object that satisfies the requirement for appearing in a constant expression and the lvalue-to-rvalue conversion is immediately applied to i. That doesn't make much sense to me, as i is clealy being used in the declaration int j = i;, as can be seen in the slightly modified code shown here, where I forced the variable i not to be optimized out of the compiled code.

Of course, there must be something wrong in my reasoning above, for I don't believe C++11 could be wrong in such a simple example. Again, what am I missing now???

Aucun commentaire:

Enregistrer un commentaire