开发者

Is assignment of braced-init-list to an array correct? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about开发者_Go百科 programming within the scope defined in the help center.

Closed 9 years ago.

Improve this question

The standard 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜