public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Value type of map need not be default copyable
@ 2012-08-03  4:18 Ollie Wild
  2012-08-03  9:39 ` Paolo Carlini
  0 siblings, 1 reply; 31+ messages in thread
From: Ollie Wild @ 2012-08-03  4:18 UTC (permalink / raw)
  To: gcc-patches, paolo.carlini; +Cc: Richard Smith, Diego Novillo, Paul Pluzhnikov

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

Patch courtesy Richard Smith at Google:

Fix bug in the implementation of std::map's operator[]. Construct an
object of type value_type, rather than using std::make_pair, so as to
allow mapped_type to have an *explicit* copy constructor.

See [map.access] (23.4.4.3)/5 for the corresponding standardese.

Tested via bootstrap + test.

Okay for trunk?

Thanks,
Ollie


2012-08-02  Ollie Wild  <aaw@google.com>
	    Richard Smith  <richardsmith@google.com>

	* include/bits/stl_map.h (operator[](key_type&&)): Replace
	std::make_pair with value_type.
	* testsuite/23_containers/map/operators/2.cc: New test.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1970 bytes --]

diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h
index cfd478a..a3abdd4 100644
--- a/libstdc++-v3/include/bits/stl_map.h
+++ b/libstdc++-v3/include/bits/stl_map.h
@@ -475,7 +475,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 	iterator __i = lower_bound(__k);
 	// __i->first is greater than or equivalent to __k.
 	if (__i == end() || key_comp()(__k, (*__i).first))
-          __i = insert(__i, std::make_pair(std::move(__k), mapped_type()));
+          __i = insert(__i, value_type(std::move(__k), mapped_type()));
 	return (*__i).second;
       }
 #endif
diff --git a/libstdc++-v3/testsuite/23_containers/map/operators/2.cc b/libstdc++-v3/testsuite/23_containers/map/operators/2.cc
new file mode 100644
index 0000000..ce633d7
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/map/operators/2.cc
@@ -0,0 +1,38 @@
+// 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/>.
+
+// 23.4.4 template class map
+
+// This test verifies that the value type of a map need not be default
+// copyable.
+
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+#include <map>
+
+struct Mapped {
+    Mapped();
+    explicit Mapped(const Mapped&);
+};
+
+Mapped & foo()
+{
+  std::map<int, Mapped> m;
+  return m[0];
+}

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

end of thread, other threads:[~2012-08-13 19:50 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03  4:18 Value type of map need not be default copyable Ollie Wild
2012-08-03  9:39 ` Paolo Carlini
2012-08-03 15:19   ` Ollie Wild
2012-08-04 11:23     ` Paolo Carlini
2012-08-04 11:54       ` Paolo Carlini
2012-08-04 13:27         ` Marc Glisse
2012-08-04 15:08           ` Paolo Carlini
2012-08-04 15:16             ` Marc Glisse
2012-08-04 15:19               ` Paolo Carlini
2012-08-04 15:28                 ` Marc Glisse
2012-08-04 15:34                   ` Paolo Carlini
2012-08-07 21:43                     ` Ollie Wild
2012-08-07 22:11                       ` Paolo Carlini
     [not found]                       ` <CAGL0aWftQAdQXjOBYSoa6fjjM64Mw9_RuTBZXh4UJqhPqmWD0g@mail.gmail.com>
2012-08-08  7:35                         ` Marc Glisse
2012-08-08 13:16                           ` François Dumont
2012-08-08 13:39                             ` Paolo Carlini
2012-08-08 20:46                               ` François Dumont
2012-08-09  7:14                                 ` Marc Glisse
2012-08-09  8:35                                   ` Paolo Carlini
2012-08-09 12:01                                     ` Jonathan Wakely
2012-08-09 20:22                                     ` François Dumont
2012-08-09 21:22                                       ` Marc Glisse
2012-08-09 23:26                                         ` Paolo Carlini
2012-08-11 13:29                                           ` François Dumont
2012-08-11 13:47                                             ` Marc Glisse
2012-08-12 11:43                                               ` Jonathan Wakely
2012-08-12 12:02                                                 ` Marc Glisse
2012-08-12 20:00                                               ` François Dumont
2012-08-13 12:10                                                 ` Paolo Carlini
2012-08-13 19:50                                                   ` François Dumont
2012-08-08 13:48                             ` Marc Glisse

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