views:

148

answers:

1

n3092 (final draft) says, under 5.17/9

A braced-init-list may appear on the right-hand side of
- an assignment to a scalar [...]
- an assignment defined by a user-defined assignment operator [..]

While in GCC 4.5.1-pre9999, I can compile this (using -std=c++0x, NOT -std=gnu++0x)

#include <iostream>
int main()
{
        int test[] = {1,2,3};
        std::cout << test[0] << test[1] << test[2];
        test = {4,5,6};
        std::cout << test[0] << test[1] << test[2] << std::endl;
}

and it prints 123456. Is GCC correct here?

+4  A: 

It looks like a bug to me. The initialization (int test = {1,2,3};) is fine, but as far as I can see, nothing in the standard allows the assignment.

Jerry Coffin
And if it were allowed, logically so should array assignment be.
anon
@Neil: indeed true.
Jerry Coffin
You were right, apparently it was a GCC bug and it was fixed in GCC 4.6: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44045#c12
Cubbi