Fail to compile: #include <array> void function(std::array<unsigned int,3> a) { } int main() { // ok std::array<unsigned int,3> vec {0, 0, 0}; // error: could not convert '{"hello", "world", "test"}' to 'std::vector...' function({0,0,0}); } -------------------- 8.5/14,16: The initialization that occurs in the form T x = a; as well as in argument passing, function return, throwing an exception (15.1), handling an exception (15.3), and aggregate member initialization (8.5.1) is called copy-initialization. . . The semantics of initializers are as follows[...]: If the initializer is a braced-init-list, the object is list-initialized (8.5.4). So it seems a bug. bastien
Works on the trunk for me ...
For me, it works everywhere, 4.7.0, 4.6.2 and current 4.7 branch included. Thus, let's ask submitter to double check or we have to close this as WORKSFORME.
bastien@bastien-debian:/tmp$ cat test.c #include <array> void function(std::array<unsigned int,3> a) { } int main() { // ok std::array<unsigned int,3> vec {0, 0, 0}; // error: could not convert '{"hello", "world", "test"}' to //'std::vector...' function({0,0,0}); } bastien@bastien-debian:/tmp$ g++-4.7 -std=c++11 test.c test.c: In function ‘int main()’: test.c:14:17: error: could not convert ‘{0, 0, 0}’ from ‘<brace-enclosed initializer list>’ to ‘std::array<unsigned int, 3ul>’ bastien@bastien-debian:/tmp$ g++-4.7 --version g++-4.7 (Debian 4.7.0-7) 4.7.0 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. So it does not work under debian testing of the day (upgraded today)
Oops, you are right, now I can reproduce, no idea what I was doing earlier today. Sorry. In any case, I can confirm what Andrew said, I cannot reproduce with mainline and, AFAICS, this isn't a regression, thus I'm going to add the testcase to the testsuite and close the PR as fixed.
Ah, I figured out what misled me: I added curly brackets to avoid -Wmissing-braces warnings, ie, function({{0, 0, 0}}), and like this not only the snippet doesn't trigger warnings, is actually accepted everywhere ;)
Author: paolo Date: Mon May 21 22:17:54 2012 New Revision: 187746 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187746 Log: 2012-05-21 Paolo Carlini <paolo.carlini@oracle.com> PR c++/53361 * testsuite/23_containers/array/cons/53361.cc: New. Added: trunk/libstdc++-v3/testsuite/23_containers/array/cons/53361.cc Modified: trunk/libstdc++-v3/ChangeLog
Closing.
This SO post claims that GCC is in error: http://stackoverflow.com/questions/8192185/using-stdarray-with-initialization-lists
(In reply to nightstrike from comment #8) > This SO post claims that GCC is in error: Yes and it was fixed in 4.8.
Oh, strange. I thought I was still experiencing this on 4.8.2. I'll check again. Sorry for the noise.