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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  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 ` paolo.carlini at oracle dot com
  2012-01-03 15:00 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03  0:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 00:18:20 UTC ---
Uhm, is it simply that cp_parser_postfix_open_square_expression doesn't handle:

  postfix-expression [ braced-init-list ]

or I'm misreading the C++11 grammar vs our parser?


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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2012-01-03 15:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2012-01-03 15:00:03 UTC ---
(In reply to comment #1)
> Uhm, is it simply that cp_parser_postfix_open_square_expression doesn't handle:
> 
>   postfix-expression [ braced-init-list ]
> 
> or I'm misreading the C++11 grammar vs our parser?

Yep, that's the problem.


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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 15:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-03
     Ever Confirmed|0                           |1

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 15:38:18 UTC ---
Confirming then.


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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  2012-01-02 23:30 [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[] akrzemi1 at gmail dot com
                   ` (2 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 17:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |paolo.carlini at oracle dot
                   |gnu.org                     |com
   Target Milestone|---                         |4.7.0

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 17:37:12 UTC ---
On it.


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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  2012-01-02 23:30 [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[] akrzemi1 at gmail dot com
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 18:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tom.prince at ualberta dot
                   |                            |net

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 18:17:10 UTC ---
*** Bug 39901 has been marked as a duplicate of this bug. ***


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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  2012-01-02 23:30 [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[] akrzemi1 at gmail dot com
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-01-03 20:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-01-03 20:25:25 UTC ---
Author: paolo
Date: Tue Jan  3 20:25:16 2012
New Revision: 182856

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182856
Log:
/gcc/cp
2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51738
    * parser.c (cp_parser_postfix_open_square_expression): Handle
    postfix-expression [ braced-init-list ].

/gcc/testsuite
2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51738
    * g++.dg/cpp0x/initlist-postfix-open-square.C: New.

/libstdc++-v3
2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51738
    * testsuite/23_containers/map/element_access/39901.cc: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist-postfix-open-square.C
    trunk/libstdc++-v3/testsuite/23_containers/map/element_access/39901.cc
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libstdc++-v3/ChangeLog


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

* [Bug c++/51738] C++11 initializer list does not work correctly with operator[]
  2012-01-02 23:30 [Bug c++/51738] New: C++11 initializer list does not work correctly with operator[] akrzemi1 at gmail dot com
                   ` (5 preceding siblings ...)
  2012-01-03 20:25 ` paolo at gcc dot gnu.org
@ 2012-01-03 20:26 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-03 20:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51738

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-03 20:26:15 UTC ---
Fixed for 4.7.0.


^ 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).