re PR c++/51738 (C++11 initializer list does not work correctly with operator[])
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 3 Jan 2012 20:25:16 +0000 (20:25 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 3 Jan 2012 20:25:16 +0000 (20:25 +0000)
/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.

From-SVN: r182856

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist-postfix-open-square.C [new file with mode: 0644]
libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/23_containers/map/element_access/39901.cc [new file with mode: 0644]

index a5387da23a57364ae8c5faf82ef74f2b94cfc9c1..f4f491debdf55dfe9afe19390760fc873307bf7a 100644 (file)
@@ -1,3 +1,9 @@
+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 ].
+
 2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/29273
index 7e6915cf40557c9bc6d459db1e1ad057c105d496..8f2357e64a0e846d462f23544230121262400fad 100644 (file)
@@ -5831,6 +5831,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
    by cp_parser_builtin_offsetof.  We're looking for
 
      postfix-expression [ expression ]
+     postfix-expression [ braced-init-list ] (C++11)
 
    FOR_OFFSETOF is set if we're being called in that context, which
    changes how we deal with integer constant expressions.  */
@@ -5856,7 +5857,16 @@ cp_parser_postfix_open_square_expression (cp_parser *parser,
   if (for_offsetof)
     index = cp_parser_constant_expression (parser, false, NULL);
   else
-    index = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+    {
+      if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
+       {
+         bool expr_nonconst_p;
+         maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
+         index = cp_parser_braced_list (parser, &expr_nonconst_p);
+       }
+      else
+       index = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+    }
 
   /* Look for the closing `]'.  */
   cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
index e7ad9005212df38937f6da2e9268563b8992c3b0..8fa86a868ebe10396b11831d088e1dac8883c3b1 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51738
+       * g++.dg/cpp0x/initlist-postfix-open-square.C: New.
+
 2012-01-03  Andrew Pinski  <apinski@cavium.com>
 
        * lib/scanasm.exp (dg-function-on-line): Always use a special format
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-postfix-open-square.C b/gcc/testsuite/g++.dg/cpp0x/initlist-postfix-open-square.C
new file mode 100644 (file)
index 0000000..38b1782
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/51738
+// { dg-options -std=c++0x }
+
+struct Index
+{
+  Index(unsigned, unsigned){ }
+};
+
+struct Matrix
+{
+  void operator[](Index){ }
+};
+
+int main()
+{
+  Matrix m;
+  m[{0,1}];
+}
index 6d1ab92f88c3536a119f0a341fad99c4873a851b..451596a2f36f5ffa36114899b2e79cf3dece044d 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51738
+       * testsuite/23_containers/map/element_access/39901.cc: New.
+
 2011-12-30  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        * doc/xml/manual/extensions.xml: Improve markup and note that some
diff --git a/libstdc++-v3/testsuite/23_containers/map/element_access/39901.cc b/libstdc++-v3/testsuite/23_containers/map/element_access/39901.cc
new file mode 100644 (file)
index 0000000..2a22494
--- /dev/null
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2012 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <map>
+#include <testsuite_hooks.h>
+
+// c++/39901
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::map<std::pair<int, int>, int> the_map;
+
+  the_map[{0, 1}] = 5;
+  VERIFY( (the_map.size() == 1) );
+  VERIFY( (the_map[{0, 1}] == 5) );
+
+  VERIFY( (the_map[{0, 0}] == 0) );
+  VERIFY( (the_map.size() == 2) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}