
Darren Cook wrote:
No. This is a common misconception and a common source of bugs that only show up when optimizations are turned on. It's also a source of exception-unsafe code, as detailed in Exceptional C++ and a GOTW column.
That kind of validates using v+=foo(),bar(); then, but also says why you shouldn't use it: a common source of bugs.
I think with an initialization library in particular people will write, and expect to always work, something like: v+= get(), get(), get();
They surely will expect this to work and it might fail if 'get()' result depend on the call order. In fact *any* convenient initialization syntax will have this problem just becase you'd have single expression, and the order of evaluation is not specified. So, the question is whether use of "," above makes user think that the order of evaluation is specified? I think it does not matter. Most users don't know about sequence points and operator,. The mostly use operator,() inside header of 'for' loop and don't think much about it. They will have specific evaluation order in mind for any syntax, for example: desc.add_options() ( get() ) ( get() ) ; So, the primary thing is avoiding unsafe 'get()'s functions, like one which modify global state or return naked pointers. - Volodya