This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51738] New: C++11 initializer list does not work correctly with operator[]
- From: "akrzemi1 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 02 Jan 2012 23:29:51 +0000
- Subject: [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[]
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738
Bug #: 51738
Summary: C++11 initializer list does not work correctly with
operator[]
Classification: Unclassified
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: akrzemi1@gmail.com
I compile the following code:
~~~~
struct Index{
Index(unsigned, unsigned){}
};
struct Matrix{
void operator[](Index){}
};
int main() {
Matrix m;
m[{0,1}];
//m.operator[]({0,1}); -- this is valid
//m[Index{0,1}]; -- this is valid
}
~~~~
I use the following command:
g++ main.cpp -Wall -Wextra -fno-strict-aliasing -fwrapv -std=c++0x -o brace.exe
I get the following reply:
main.cpp: In function âint main()â:
main.cpp:11:5: error: expected primary-expression before â{â token
main.cpp:11:5: error: expected â]â before â{â token
main.cpp:11:5: error: expected â;â before â{â token
main.cpp:11:10: error: expected primary-expression before â]â token
main.cpp:11:10: error: expected â;â before â]â token
This is a bug because my program is valid C++11 code, and if I write:
m.operator[]({0,1});
instead of
m[{0,1}];
my program compiles.
This has been already reported in bug report 39901, but 39901 has been
incorrectly put into "RESOLVED INVALID"state. Code:
m[{0,1}];
should be equivalent to:
m[Index{0,1}];
Regards,
&rzej