Currently libc++ implements some operations on valarray by using the
resize method. This method has a parameter with a default value.
Because of this, valarray may spuriously construct and destruct
objects of valarray's element type.
This patch fixes this issue and adds corresponding test cases.
I thought that you had lost an exception guarantee here, but it turns out that there wasn't one before. If the allocation fails, you are left with an empty array instead of the old contents.