public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[]
@ 2012-01-02 23:30 akrzemi1 at gmail dot com
  2012-01-03  0:18 ` [Bug c++/51738] " paolo.carlini at oracle dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: akrzemi1 at gmail dot com @ 2012-01-02 23:30 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-01-03 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-02 23:30 [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[] akrzemi1 at gmail dot com
2012-01-03  0:18 ` [Bug c++/51738] " paolo.carlini at oracle dot com
2012-01-03 15:00 ` jason at gcc dot gnu.org
2012-01-03 15:38 ` paolo.carlini at oracle dot com
2012-01-03 17:37 ` paolo.carlini at oracle dot com
2012-01-03 18:18 ` paolo.carlini at oracle dot com
2012-01-03 20:25 ` paolo at gcc dot gnu.org
2012-01-03 20:26 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).