Bug 39901 - [C++0x] Initializer list not allowed in []
Summary: [C++0x] Initializer list not allowed in []
Status: RESOLVED DUPLICATE of bug 51738
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-25 21:26 UTC by tom.prince
Modified: 2012-01-03 18:17 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-01-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tom.prince 2009-04-25 21:26:49 UTC
According to n2531, the new C++0x initializer-list is allowed in []. 

Test Case:

#include <map>

void test(void)
{
        std::map<std::pair<int,int>,int> the_map;
        the_map[{0,1}] = 5;
}

Error:
/tmp/test.cc: In function ‘void test()’:
/tmp/test.cc:6: error: expected primary-expression before ‘{’ token
/tmp/test.cc:6: error: expected ‘]’ before ‘{’ token
/tmp/test.cc:6: error: expected ‘;’ before ‘{’ token
/tmp/test.cc:6: error: expected primary-expression before ‘]’ token
/tmp/test.cc:6: error: expected ‘;’ before ‘]’ token

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-languages=c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-multilib --disable-bootstrap --prefix /Users/cougar/local/gcc45 : (reconfigured) ./config
ure --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-multilib --disable-bootstrap --prefix /Users/cougar/local/gcc45 --enable-languages=c,c++ --no-create --no-recursion
Thread model: posix
gcc version 4.5.0 20090425 (experimental) (GCC)
Comment 1 Paolo Carlini 2009-04-25 22:30:25 UTC
Jason, can you have a look? Thanks.
Comment 2 Paolo Carlini 2009-07-31 16:16:58 UTC
I'm sorry Jason, a ping... ;)
Comment 3 Paolo Carlini 2009-07-31 16:26:11 UTC
Actually, this one seems invalid to me: std::map does *not* define an operator[](std::initializer_list<>). Waiting a bit for Jason to confirm, then closing.
Comment 4 Paolo Carlini 2009-08-01 18:12:14 UTC
Closing.
Comment 5 j deck 2010-08-02 01:22:21 UTC
how is this invalid?

it shouldn't matter whether map defines operator[](std::initializer_list<>), only operator[](std::pair<int,int>) for std::map<std::pair<int,int>,int>.

{1, 2} should then be used to initialize that pair.
Comment 6 Paolo Carlini 2012-01-03 18:16:27 UTC
Re-open...
Comment 7 Paolo Carlini 2012-01-03 18:17:10 UTC
... and resolve again as duplicate.

*** This bug has been marked as a duplicate of bug 51738 ***