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

Сообщение Re[54]: Зачем плюс? от 03.12.2018 19:59

Изменено 03.12.2018 20:04 σ

Re[54]: Зачем плюс?
σ>>>>Можно цитаты?
NI>>>Цитаты чего?
σ>>Разработчиков.

NI>Примерно полтора года назад данные правила вместе с примером кода разбирались на рефлекторе комитета по стандартизации, разъяснения давал автор этих правил — Ричард Смит (обсуждение закрытое, так что ссылку дать не смогу).


Аха. Вот тебя и сдеанонили, Коля.

NI>N.I.: The wording "the initializer expression is used to initialize the destination object" seems to say nothing certain about _how_ exactly the expression is used to initialize the destination object. So, what is it supposed to mean? Should it mean that if the initializer expression denotes some object, then the destination object must be the same object as the one denoted by the initializer expression?


NI>R.S.: If the initializer expression is a prvalue, there is no other object; you're using two different terms in your question to refer to objects that are the same by definition. Please consult the definition of prvalue in [basic.lval]/1.2. Note in particular that a prvalue does not itself create an object; the object is provided by the context in which the prvalue is evaluated. [Из этого коммента я делаю вывод, что чел либо не понимает разницу между формальными и неформальными описаниями, либо считает, что строгая формализация в данном случае не требуется, ибо "и так всё понятно"].


Ну вообще мне тоже кажется, что определения prvalue и его result (object) вполне достаточно для понимания правила про инициализацию.
А формализация? Можно всё, что не формально описанная операционная/денотационная семантика, назвать неформальным.

NI>N.I.:

NI>***
NI>When an object of class type X is passed to or returned from a function, if each copy constructor, move constructor, and destructor of X is either trivial or deleted, and X has at least one non-deleted copy or move constructor, implementations are permitted to create a temporary object to hold the function parameter or result object. The temporary object is constructed from the function argument or return value, respectively, and the function’s parameter or return object is initialized as if by using the non-deleted trivial constructor to copy the temporary (even if that constructor is inaccessible or would not be selected by overload resolution to perform a copy or move of the object).
NI>***

NI>which implies that the source object and the destination object may be two distinct objects allocated at different addresses.


NI>R.S: That's correct; [class.temporary]/3 specifies an (optional) exception to the general rule. Note that it explicitly says that the implementation creates an additional temporary object in this case.


NI>N.I.: This can be observed in a program like this:


NI><дальше приводится такая же программа, что я тут продемонстрировал выше>


NI>If the initially created temporary is copied, the field p of a copy does not point to a valid array object (data) and an attempt to access the value of x.p results in undefined behavior.


NI>R.S.: Right. This is a design error in class X. [Тут он, видимо, имел в виду, что перемещающий конструктор X следовало определить должным образом]


Ок, буду знать, что этот параграф оставлен намеренно.
Re[54]: Зачем плюс?
σ>>>>Можно цитаты?
NI>>>Цитаты чего?
σ>>Разработчиков.

NI>Примерно полтора года назад данные правила вместе с примером кода разбирались на рефлекторе комитета по стандартизации, разъяснения давал автор этих правил — Ричард Смит (обсуждение закрытое, так что ссылку дать не смогу).


У меня есть доступ в рид-онли.

NI>N.I.: The wording "the initializer expression is used to initialize the destination object" seems to say nothing certain about _how_ exactly the expression is used to initialize the destination object. So, what is it supposed to mean? Should it mean that if the initializer expression denotes some object, then the destination object must be the same object as the one denoted by the initializer expression?


NI>R.S.: If the initializer expression is a prvalue, there is no other object; you're using two different terms in your question to refer to objects that are the same by definition. Please consult the definition of prvalue in [basic.lval]/1.2. Note in particular that a prvalue does not itself create an object; the object is provided by the context in which the prvalue is evaluated. [Из этого коммента я делаю вывод, что чел либо не понимает разницу между формальными и неформальными описаниями, либо считает, что строгая формализация в данном случае не требуется, ибо "и так всё понятно"].


Ну вообще мне тоже кажется, что определения prvalue и его result (object) вполне достаточно для понимания правила про инициализацию.
А формализация? Можно всё, что не формально описанная операционная/денотационная семантика, назвать неформальным.

NI>N.I.:

NI>***
NI>When an object of class type X is passed to or returned from a function, if each copy constructor, move constructor, and destructor of X is either trivial or deleted, and X has at least one non-deleted copy or move constructor, implementations are permitted to create a temporary object to hold the function parameter or result object. The temporary object is constructed from the function argument or return value, respectively, and the function’s parameter or return object is initialized as if by using the non-deleted trivial constructor to copy the temporary (even if that constructor is inaccessible or would not be selected by overload resolution to perform a copy or move of the object).
NI>***

NI>which implies that the source object and the destination object may be two distinct objects allocated at different addresses.


NI>R.S: That's correct; [class.temporary]/3 specifies an (optional) exception to the general rule. Note that it explicitly says that the implementation creates an additional temporary object in this case.


NI>N.I.: This can be observed in a program like this:


NI><дальше приводится такая же программа, что я тут продемонстрировал выше>


NI>If the initially created temporary is copied, the field p of a copy does not point to a valid array object (data) and an attempt to access the value of x.p results in undefined behavior.


NI>R.S.: Right. This is a design error in class X. [Тут он, видимо, имел в виду, что перемещающий конструктор X следовало определить должным образом]


Ок, буду знать, что этот параграф оставлен намеренно.