https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110102
Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|13.2 |--- --- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> --- (In reply to Arthur O'Dwyer from comment #4) > My first, reduced, example, where `std::list<A> v = {1,2,3}` is accepted for > move-only type `A`, is 100% a bug and should be fixed. But that is easy to > fix. It's pedantically a bug, but only because of the suboptimal specified initializer_list semantics. Just looking at that line I expect a list of As initialized from integers; I don't expect that initialization to involve an unnecessary copy. It's also unfortunate that initialization from a prvalue initializer_list can't use the A move constructor. > struct NthPrime { constexpr NthPrime(int); ... }; > std::vector<NthPrime> primes = {1,2,3,4,5,6}; > Here we *want* to make an initializer_list<NthPrime> backed by a static > array of NthPrime at compile time. If we make an initializer_list<int>, then > we'll have to run the NthPrime(int) constructor at runtime, and that's > expensive. > I tried out this example on Godbolt and the optimizer made the correct > choice in this specific case, so that's good. Right, we don't do this transformation if the initializer_list backing array would be constant.