Talk:cpp/language/list initialization

Should this page mention (clearly) that the expressions in the initializer list are evaluated in the order they are listed? And perhaps it should note how that's different from a simple function call, possibly of the same constructor in some cases, with instead of {}?

See also these relevant compiler bug fixes in this area.


 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253
 * https://blogs.msdn.microsoft.com/vcblog/2016/02/11/compiler-improvements-in-vs-2015-update-2/ ("Order of initializer list")

I couldn't tell from reading this page and the related pages that this was guaranteed.

--BradSpencer (talk) 14:08, 25 October 2016 (PDT)
 * cpp/language/eval_order says that, at "10) In list-initialization, every value computation and side effect...". I agree it should be on this page as well (added as the first entry in Notes) --Cubbi (talk) 14:14, 25 October 2016 (PDT)

The example for this page states on one line that "double d = double{1.2}; // list-initialization of a temporary, then copy-init". An example for a class type would be helpful here too. For example: T d = T{arg1, arg2,..}, where T is a class type. I'm looking on the site for the clear, specific example but can't find it. (Would it then qualify for copy elision since C++17 under Copy initialization rules?)
 * Added. I use "prvalue" instead of "temporary" whenever the temporary is not created in C++17. --Fruderica (talk) 21:33, 15 August 2020 (PDT)