What is a temporary object with static storage duration

后端 未结 1 461
孤街浪徒
孤街浪徒 2021-01-17 10:51

Inspired from this answer, from [expr.const]

A constant expression is either a glvalue core constant expression that refers to an entity that is a permit

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 11:30

    [basic.stc]/1 tells us:

    The storage duration is the property of an object that defines the minimum potential lifetime of the storage containing the object.

    So every object has a storage duration. Further, paragraph 2 says:

    Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.1) and implicitly created by the implementation (15.2).

    Emphasis added. Note that section 15.2 is [class.temporary]: the rules for temporary objects.

    Therefore, we can conclude that temporary objects have storage durations. And we can conclude that temporaries must have one of those storage durations. Indeed, there are numerous references in the standard to "variables or temporary objects" and their storage durations.

    However, despite this clearly saying that temporary objects have one of those storage durations... the standard never actually says what storage duration they have. [class.temporary] does not have a statement saying that temporaries bound to references have the storage duration of their references. And [basic.stc]'s explanation of static, automatic, and thread-local durations always speaks of variables.

    So I would say that this is a defect in the wording. It seems clear that the standard expects temporaries to have an appropriate storage duration; there are multiple places where the standard talks about the storage duration of variable or temporary objects. But it never says what storage duration they actually have.

    0 讨论(0)
提交回复
热议问题