C++ Logo

std-discussion

Advanced search

Re: Odr-use

From: Bo Persson <bo_at_[hidden]>
Date: Thu, 14 Nov 2024 14:33:37 +0100
On 2024-11-14 at 14:22, Russell Shaw via Std-Discussion wrote:
> On 14/11/24 22:47, Ville Voutilainen wrote:
>> On Thu, 14 Nov 2024 at 13:09, Russell Shaw via Std-Discussion
>> <std-discussion_at_[hidden]> wrote:
>>
>>> So "struct S { static const int x = 0; };" 'defines' 'S::x' because
>>> it has an
>>> initializer, yet has no memory location ?
>>
>> Right, it has no memory location, but the value is known, and known
>> not to change, so anything
>> that just uses the value but doesn't need the address can simply be
>> replaced by that value.
>
> Later, it says:
>
> "A structured binding is odr-used if it appears as a potentially-
> evaluated expression."
>
> --------------------------
> int a[1];
>
> auto [x] = a; <---- (A)
> --------------------------
>
> Is (A) the "structured binding" and "potentially-evaluated
> expression." ? Or a declaration ?
>
> Or is 'x' the "structured binding" ?

This is way out in the corner, but x works like a reference (similar to
the parameter in the earlier example).

If you use x, that reference must be valid, but if you just declare it
and never use it (Why would you?), apparently you get away with the
"reference" not really working.

I wouldn't bother too much with getting the exact details. :-)

Received on 2024-11-14 13:33:39