samedi 25 juin 2022

c++11 is it safe to return an intializer_list value? [duplicate]

I've this simple function:

initializer_list<int> f(){return {1,2,3};}

g++ gives a warning saying:

warning: returning temporary initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime]

Is there any risk to return an {1, 2, 3}? Thanks for explanations!

Aucun commentaire:

Enregistrer un commentaire