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: [email protected]
ReportedBy: [email protected]
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