Bug 53361 - Could not convert ‘{0, 0, 0}’ from ‘<brace-enclosed initializer list>’ to ‘std::array<unsigned int, 3ul>’
Summary: Could not convert ‘{0, 0, 0}’ from ‘<brace-enclosed initializer list>’ to ‘st...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 minor
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-15 14:57 UTC by Bastien ROUCARIES
Modified: 2014-07-22 05:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.0
Known to fail:
Last reconfirmed: 2012-05-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bastien ROUCARIES 2012-05-15 14:57:24 UTC
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
Comment 1 Andrew Pinski 2012-05-15 17:48:58 UTC
Works on the trunk for me ...
Comment 2 Paolo Carlini 2012-05-21 15:36:15 UTC
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.
Comment 3 Bastien ROUCARIES 2012-05-21 21:19:35 UTC
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)
Comment 4 Paolo Carlini 2012-05-21 21:36:10 UTC
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.
Comment 5 Paolo Carlini 2012-05-21 21:50:33 UTC
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 ;)
Comment 6 paolo@gcc.gnu.org 2012-05-21 22:18:05 UTC
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
Comment 7 Paolo Carlini 2012-05-21 22:19:13 UTC
Closing.
Comment 8 nightstrike 2014-07-22 03:23:07 UTC
This SO post claims that GCC is in error:

http://stackoverflow.com/questions/8192185/using-stdarray-with-initialization-lists
Comment 9 Andrew Pinski 2014-07-22 05:31:44 UTC
(In reply to nightstrike from comment #8)
> This SO post claims that GCC is in error:


Yes and it was fixed in 4.8.
Comment 10 nightstrike 2014-07-22 05:34:10 UTC
Oh, strange.  I thought I was still experiencing this on 4.8.2.  I'll check again.  Sorry for the noise.