1

Before you answer, observe that another question is closely related.

The C++17 standard (draft here), sect. 6.2(2.8), gives the following example:

struct S { static const int x = 0; };
const int &f(const int &r);
int n = b ? (1, S::x) // S::x is not odr-used here
          : f(S::x);  // S::x is odr-used here, so a definition is required

The example's "odr" means, "one-definition rule," but the example's comment, "S::x is not odr-used here," looks like nonsense to me. Is it?

I am no language lawyer but, unfortunately, the comment conveys no plausible or approximate idea to me. This suggests that I am missing a concept.

On the other hand, a 1600-page document like the C++17 standard can make some mistakes. I do not criticize but merely wish to ensure that I have understood.

Is the comment nonsense or does it mean something sensible? How or why, please?

thb
  • 13,796
  • 3
  • 40
  • 68
  • 1
    Looks to be explained in the top answer here: https://stackoverflow.com/questions/23491781/when-is-a-variable-odr-used-in-c14 – NathanOliver Feb 13 '19 at 16:33
  • 2
    Applying the lvalue-to-rvalue conversion to `S::x` yields a constant expression, so `S::x` is not odr-used per `[basic.def.odr]/4` and `[expr.const]/2.7`. – YSC Feb 13 '19 at 16:37
  • I could copy/paste my deleted answer of the linked question here tbh. – YSC Feb 13 '19 at 16:37
  • @NathanOliver Oh, I see. I would not have found that earlier answer if you did not point me toward it. In view of the earlier answer, the example I quoted revealed no major concept but merely illustrated a minor point regarding `static const` data members. Thus, I was worried about nothing. Thank you for the link. – thb Feb 13 '19 at 16:43
  • 2
    Note that the technical term being used in the explication of that code is "odr-used", not "odr". "odr-used" means used in a way that triggers the application of the odr. – Pete Becker Feb 13 '19 at 16:54

0 Answers0