Информация об изменениях

Сообщение Re[9]: Правомерно ли такое от 18.08.2020 22:30

Изменено 18.08.2020 23:02 σ

Re[9]: Правомерно ли такое
R>Во-первых, деструктор формально есть у любого типа данных, даже у int. И его даже можно явно позвать: http://coliru.stacked-crooked.com/a/8360b8eef0155e2c. Просто деструктор такая хитрая штука, что он может быть определен пользователем, а может быть сгенерирован компилятором. Деструктор может быть тривиальным и нетривиальным. Но он есть всегда. И время жизни объекта, согласно стандарту, закачивается, ПРИ ВХОДЕ, в деструктор (даже если он формальный — в этом случае просто где вход, там и выход).

Итак, смотрим в C++17 [expr.pseudo]/1:
> The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for the non-class type denoted by type-name or decltype-specifier. The result shall only be used as the operand for the function call operator (), and the result of such a call has type void. The only effect is the evaluation of the postfix-expression before the dot or arrow.

Никаких вызовов деструкторов (для int) и окончания его жизни...

Да, в C++20 закрыли одно CWG issue и ЕМНИП приняли его решение в статусе дефект репорта (т.е. с ретроактивным применением), но никаких вызовов деструкторов для `int` не появилось.
[expr.call]/5:
> If the postfix-expression names a pseudo-destructor (in which case the postfix-expression is a possibly-parenthesized class member access), the function call destroys the object of scalar type denoted by the object expression of the class member access ([expr.ref], [basic.life]).
[basic.life]/1:
> The lifetime of an object o of type T ends when:
> — if T is a non-class type, the object is destroyed, or
> — if T is a class type, the destructor call starts, or
> — the storage which the object occupies is released, or is reused by an object that is not nested within o ([intro.object]).
Re[9]: Правомерно ли такое
R>Во-первых, деструктор формально есть у любого типа данных, даже у int. И его даже можно явно позвать: http://coliru.stacked-crooked.com/a/8360b8eef0155e2c. Просто деструктор такая хитрая штука, что он может быть определен пользователем, а может быть сгенерирован компилятором. Деструктор может быть тривиальным и нетривиальным. Но он есть всегда. И время жизни объекта, согласно стандарту, закачивается, ПРИ ВХОДЕ, в деструктор (даже если он формальный — в этом случае просто где вход, там и выход).

Итак, смотрим в C++17 [expr.pseudo]/1:
> The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for the non-class type denoted by type-name or decltype-specifier. The result shall only be used as the operand for the function call operator (), and the result of such a call has type void. The only effect is the evaluation of the postfix-expression before the dot or arrow.

Никаких вызовов деструкторов (для int) и окончания его жизни...

Да, в C++20 закрыли одно CWG issue и ЕМНИП применили его решение ретроактивно, но никаких вызовов деструкторов для `int` не появилось.
[expr.call]/5:
> If the postfix-expression names a pseudo-destructor (in which case the postfix-expression is a possibly-parenthesized class member access), the function call destroys the object of scalar type denoted by the object expression of the class member access ([expr.ref], [basic.life]).
[basic.life]/1:
> The lifetime of an object o of type T ends when:
> — if T is a non-class type, the object is destroyed, or
> — if T is a class type, the destructor call starts, or
> — the storage which the object occupies is released, or is reused by an object that is not nested within o ([intro.object]).