C++ Logo

std-discussion

Advanced search

Re: Odr-use

From: Russell Shaw <rjshaw_at_[hidden]>
Date: Thu, 14 Nov 2024 22:09:27 +1100
On 14/11/24 21:14, Bo Persson via Std-Discussion wrote:
> On 2024-11-14 at 11:07, Russell Shaw via Std-Discussion wrote:
>> Hi,
>>
>> In 14882:2024 at point [A], why is "S::x is not odr-used here" ?
>>
>> "Odr-use" is not explained well.
>>
>> ------------------------------------------------
>> 6.3 One-definition rule [basic.def.odr]
>>
>> example 1
>>
>> In the following example, the set of potential results of the initializer of n
>> contains the first S::x subexpression, but not the second S::x subexpression.
>>
>> 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 <------ [A]
>> : f(S::x); // S::x is odr-used here, so a definition is required
>> ------------------------------------------------
>
> The function f takes a reference parameter. That requires S::x to *have* an
> address, so it can be referred to. Just using its value does not require it to
> be stored anywhere.

Ok.

So "struct S { static const int x = 0; };" 'defines' 'S::x' because it has an
initializer, yet has no memory location ?

Received on 2024-11-14 11:09:38