On 3/17/2017 8:21 PM, Paavo Helde wrote:
> On 17.03.2017 17:59, Alf P. Steinbach wrote:
>> On 17-Mar-17 3:45 PM, Paavo Helde wrote:
>>> On 17.03.2017 3:23, Manfred wrote:
>>>>>
>>>> True, but I would note that in the case of move constructors this is
>>>> not
>>>> only a performance issue.
>>>> When, thanks to noexcept, a move constructor is called instead of a
>>>> copy
>>>> constructor, this is also a change in semantics.
>>>
>>> There is a special clause in the standard (12.8/31) allowing the
>>> compiler to elide any copy and move constructors, even if they have side
>>> effects. Any program whose semantics depend on these things called or
>>> not called is thus extremely fragile.
>>
>> I think you misunderstand.
>>
>> Manfred is not talking about the usual elision but about the
>> `std::vector`'s choice about what to call.
Indeed
>
> I just wanted to stress than for a sanely written program there would be
> no difference (other than performance-wise, potentially) what
> std::vector decides to call or not to call when resizing the buffer.
Agreed. Only I would say that for a /well written/ program there would
be no difference. (I would agree that code that would be affected by
such difference would be bad - I wouldn't go as far as /insane/)
>
> Maybe I should expand my opinion a bit more: any program whose semantics
> depend on the copy or move constructors called or not called, or having
> exception-throwing move constructors or destructors, is extremely fragile.
>
I would agree that code that /depends/ on the difference in semantics
between copy and move is fragile, but still there /is/ a difference
between them.
Coming back to the original issue, I think that it is reductive to
classify "noexcept" as a matter of optimization:
if you use 'inline', or switch between -O0 and -O2 you can rely on the
fact that legal code will behave identically, except possibly for
runtime performance;
if you use 'noexcept' you are actually changing the behaviour of code.