xref: /OK3568_Linux_fs/buildroot/package/odb/0007-Switch-to-C-11-get-rid-of-auto_ptr-use.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From c5bea9562929c6b55ca208a530ae80033eeb1614 Mon Sep 17 00:00:00 2001
2From: Boris Kolpackov <boris@codesynthesis.com>
3Date: Tue, 7 Nov 2017 10:37:53 +0200
4Subject: [PATCH] Switch to C++11, get rid of auto_ptr use
5
6[Upstream: 6e374de9ae2f2978f2fca3390aba4ea3f72bfade]
7Signed-off-by: Kamel Bouhara <kamel.bouhara@bootlin.com>
8---
9 odb/Makefile.am   |  5 +++++
10 odb/context.cxx   |  4 ++--
11 odb/context.hxx   |  4 ++--
12 odb/generator.cxx | 18 +++++++++---------
13 odb/options.cli   |  4 ++--
14 odb/parser.cxx    | 14 ++++++++++----
15 odb/parser.hxx    |  7 ++++---
16 odb/plugin.cxx    | 10 +++++-----
17 odb/processor.cxx |  6 +++---
18 odb/validator.cxx |  2 +-
19 10 files changed, 43 insertions(+), 31 deletions(-)
20
21diff --git a/odb/Makefile.am b/odb/Makefile.am
22index 2f01398..d9e83d7 100644
23--- a/odb/Makefile.am
24+++ b/odb/Makefile.am
25@@ -9,6 +9,11 @@ plugin_LTLIBRARIES = odb.la
26
27 AM_CPPFLAGS = -I'$(top_builddir)' -I'$(top_srcdir)'
28
29+# Note: not passed by libtool when linking odb.so. Seems to be harmless for
30+# now.
31+#
32+AM_CXXFLAGS = -std=c++0x
33+
34 EXTRA_DIST = common-query.hxx common.hxx context.hxx context.ixx cxx-lexer.hxx cxx-token.hxx diagnostics.hxx emitter.hxx features.hxx gcc-fwd.hxx gcc.hxx generate.hxx generator.hxx instance.hxx location.hxx lookup.hxx option-functions.hxx option-parsers.hxx option-types.hxx options.hxx options.ixx parser.hxx pragma.hxx processor.hxx profile.hxx relational/common-query.hxx relational/common.hxx relational/common.txx relational/context.hxx relational/context.ixx relational/generate.hxx relational/header.hxx relational/inline.hxx relational/model.hxx relational/mssql/common.hxx relational/mssql/context.hxx relational/mysql/common.hxx relational/mysql/context.hxx relational/oracle/common.hxx relational/oracle/context.hxx relational/pgsql/common.hxx relational/pgsql/context.hxx relational/processor.hxx relational/schema-source.hxx relational/schema.hxx relational/source.hxx relational/sqlite/common.hxx relational/sqlite/context.hxx relational/validator.hxx semantics.hxx semantics/class-template.hxx semantics/class.hxx semantics/derived.hxx semantics/elements.hxx semantics/elements.ixx semantics/enum.hxx semantics/fundamental.hxx semantics/namespace.hxx semantics/relational.hxx semantics/relational/changelog.hxx semantics/relational/changeset.hxx semantics/relational/column.hxx semantics/relational/deferrable.hxx semantics/relational/elements.hxx semantics/relational/elements.txx semantics/relational/foreign-key.hxx semantics/relational/index.hxx semantics/relational/key.hxx semantics/relational/model.hxx semantics/relational/name.hxx semantics/relational/primary-key.hxx semantics/relational/table.hxx semantics/template.hxx semantics/union-template.hxx semantics/union.hxx semantics/unit.hxx sql-lexer.hxx sql-lexer.ixx sql-token.hxx sql-token.ixx traversal.hxx traversal/class-template.hxx traversal/class.hxx traversal/derived.hxx traversal/elements.hxx traversal/enum.hxx traversal/fundamental.hxx traversal/namespace.hxx traversal/relational.hxx traversal/relational/changelog.hxx traversal/relational/changeset.hxx traversal/relational/column.hxx traversal/relational/elements.hxx traversal/relational/foreign-key.hxx traversal/relational/index.hxx traversal/relational/key.hxx traversal/relational/model.hxx traversal/relational/primary-key.hxx traversal/relational/table.hxx traversal/template.hxx traversal/union-template.hxx traversal/union.hxx traversal/unit.hxx validator.hxx version.hxx options.cli
35
36 # Plugin.
37diff --git a/odb/context.cxx b/odb/context.cxx
38index d62fa88..87f1c32 100644
39--- a/odb/context.cxx
40+++ b/odb/context.cxx
41@@ -564,14 +564,14 @@ namespace
42   };
43 }
44
45-auto_ptr<context>
46+unique_ptr<context>
47 create_context (ostream& os,
48                 semantics::unit& unit,
49                 options const& ops,
50                 features& f,
51                 semantics::relational::model* m)
52 {
53-  auto_ptr<context> r;
54+  unique_ptr<context> r;
55
56   switch (ops.database ()[0])
57   {
58diff --git a/odb/context.hxx b/odb/context.hxx
59index 351bc61..10de237 100644
60--- a/odb/context.hxx
61+++ b/odb/context.hxx
62@@ -13,7 +13,7 @@
63 #include <stack>
64 #include <vector>
65 #include <string>
66-#include <memory>  // std::auto_ptr
67+#include <memory>  // std::unique_ptr
68 #include <ostream>
69 #include <cstddef> // std::size_t
70 #include <iostream>
71@@ -1691,7 +1691,7 @@ private:
72
73 // Create concrete database context.
74 //
75-std::auto_ptr<context>
76+std::unique_ptr<context>
77 create_context (std::ostream&,
78                 semantics::unit&,
79                 options const&,
80diff --git a/odb/generator.cxx b/odb/generator.cxx
81index 6aa5151..266b75f 100644
82--- a/odb/generator.cxx
83+++ b/odb/generator.cxx
84@@ -4,7 +4,7 @@
85
86 #include <cctype>  // std::toupper, std::is{alpha,upper,lower}
87 #include <string>
88-#include <memory>  // std::auto_ptr
89+#include <memory>  // std::unique_ptr
90 #include <iomanip>
91 #include <fstream>
92 #include <sstream>
93@@ -141,7 +141,7 @@ generate (options const& ops,
94
95     if (gen_schema)
96     {
97-      auto_ptr<context> ctx (create_context (cerr, unit, ops, fts, 0));
98+      unique_ptr<context> ctx (create_context (cerr, unit, ops, fts, 0));
99
100       switch (db)
101       {
102@@ -471,7 +471,7 @@ generate (options const& ops,
103     //
104     if (gen_cxx)
105     {
106-      auto_ptr<context> ctx (
107+      unique_ptr<context> ctx (
108         create_context (hxx, unit, ops, fts, model.get ()));
109
110       sloc_filter sloc (ctx->os);
111@@ -581,7 +581,7 @@ generate (options const& ops,
112     //
113     if (gen_cxx)
114     {
115-      auto_ptr<context> ctx (
116+      unique_ptr<context> ctx (
117         create_context (ixx, unit, ops, fts, model.get ()));
118
119       sloc_filter sloc (ctx->os);
120@@ -641,7 +641,7 @@ generate (options const& ops,
121     //
122     if (gen_cxx && (db != database::common || md == multi_database::dynamic))
123     {
124-      auto_ptr<context> ctx (
125+      unique_ptr<context> ctx (
126         create_context (cxx, unit, ops, fts, model.get ()));
127
128       sloc_filter sloc (ctx->os);
129@@ -734,7 +734,7 @@ generate (options const& ops,
130     //
131     if (gen_sep_schema)
132     {
133-      auto_ptr<context> ctx (
134+      unique_ptr<context> ctx (
135         create_context (sch, unit, ops, fts, model.get ()));
136
137       sloc_filter sloc (ctx->os);
138@@ -799,7 +799,7 @@ generate (options const& ops,
139     //
140     if (gen_sql_schema)
141     {
142-      auto_ptr<context> ctx (
143+      unique_ptr<context> ctx (
144         create_context (sql, unit, ops, fts, model.get ()));
145
146       switch (db)
147@@ -865,7 +865,7 @@ generate (options const& ops,
148         //
149         {
150           ofstream& mig (*mig_pre[i]);
151-          auto_ptr<context> ctx (create_context (mig, unit, ops, fts, 0));
152+          unique_ptr<context> ctx (create_context (mig, unit, ops, fts, 0));
153
154           switch (db)
155           {
156@@ -908,7 +908,7 @@ generate (options const& ops,
157         //
158         {
159           ofstream& mig (*mig_post[i]);
160-          auto_ptr<context> ctx (create_context (mig, unit, ops, fts, 0));
161+          unique_ptr<context> ctx (create_context (mig, unit, ops, fts, 0));
162
163           switch (db)
164           {
165diff --git a/odb/options.cli b/odb/options.cli
166index cf278cb..c994975 100644
167--- a/odb/options.cli
168+++ b/odb/options.cli
169@@ -211,10 +211,10 @@ class options
170      \cb{db pointer} pragma will use this pointer by default. The value
171      of this option can be \cb{*} which denotes the raw pointer and is
172      the default, or qualified name of a smart pointer class template,
173-     for example, \cb{std::auto_ptr}. In the latter case, the ODB compiler
174+     for example, \cb{std::shared_ptr}. In the latter case, the ODB compiler
175      constructs the object or view pointer by adding a single template
176      argument of the object or view type to the qualified name, for example
177-     \cb{std::auto_ptr<object>}. The ODB runtime uses object and view
178+     \cb{std::shared_ptr<object>}. The ODB runtime uses object and view
179      pointers to return, and, in case of objects, pass and cache
180      dynamically allocated instances of object and view types.
181
182diff --git a/odb/parser.cxx b/odb/parser.cxx
183index 927063b..30e45af 100644
184--- a/odb/parser.cxx
185+++ b/odb/parser.cxx
186@@ -26,7 +26,7 @@ public:
187
188   impl (options const&, loc_pragmas&, ns_loc_pragmas&, decl_pragmas&);
189
190-  auto_ptr<unit>
191+  unique_ptr<unit>
192   parse (tree global_scope, path const& main_file);
193
194 private:
195@@ -728,10 +728,10 @@ impl (options const& ops,
196 {
197 }
198
199-auto_ptr<unit> parser::impl::
200+unique_ptr<unit> parser::impl::
201 parse (tree global_scope, path const& main_file)
202 {
203-  auto_ptr<unit> u (new unit (main_file));
204+  unique_ptr<unit> u (new unit (main_file));
205   u->insert (global_namespace, *u);
206   process_named_pragmas (global_namespace, *u);
207
208@@ -2263,6 +2263,12 @@ fq_scope (tree decl)
209 // parser
210 //
211
212+parser::
213+~parser ()
214+{
215+  // Needs parser::impl definition.
216+}
217+
218 parser::
219 parser (options const& ops,
220         loc_pragmas& lp,
221@@ -2272,7 +2278,7 @@ parser (options const& ops,
222 {
223 }
224
225-auto_ptr<unit> parser::
226+unique_ptr<unit> parser::
227 parse (tree global_scope, path const& main_file)
228 {
229   return impl_->parse (global_scope, main_file);
230diff --git a/odb/parser.hxx b/odb/parser.hxx
231index 80e4aa4..648337f 100644
232--- a/odb/parser.hxx
233+++ b/odb/parser.hxx
234@@ -7,7 +7,7 @@
235
236 #include <odb/gcc.hxx>
237
238-#include <memory>  // std::auto_ptr
239+#include <memory>  // std::unique_ptr
240
241 #include <odb/pragma.hxx>
242 #include <odb/options.hxx>
243@@ -18,9 +18,10 @@ class parser
244 public:
245   class failed {};
246
247+  ~parser ();
248   parser (options const&, loc_pragmas&, ns_loc_pragmas&, decl_pragmas&);
249
250-  std::auto_ptr<semantics::unit>
251+  std::unique_ptr<semantics::unit>
252   parse (tree global_scope, semantics::path const& main_file);
253
254 private:
255@@ -31,7 +32,7 @@ private:
256
257 private:
258   class impl;
259-  std::auto_ptr<impl> impl_;
260+  std::unique_ptr<impl> impl_;
261 };
262
263 #endif // ODB_PARSER_HXX
264diff --git a/odb/plugin.cxx b/odb/plugin.cxx
265index 779faed..0fac632 100644
266--- a/odb/plugin.cxx
267+++ b/odb/plugin.cxx
268@@ -8,7 +8,7 @@
269 #include <sys/types.h> // stat
270 #include <sys/stat.h>  // stat
271
272-#include <memory>  // std::auto_ptr
273+#include <memory>  // std::unique_ptr
274 #include <string>
275 #include <vector>
276 #include <cstring> // std::strcpy, std::strstr
277@@ -39,7 +39,7 @@ using cutl::fs::invalid_path;
278 typedef vector<path> paths;
279
280 int plugin_is_GPL_compatible;
281-auto_ptr<options const> options_;
282+unique_ptr<options const> options_;
283 paths profile_paths_;
284 path file_;    // File being compiled.
285 paths inputs_; // List of input files in at-once mode or just file_.
286@@ -222,7 +222,7 @@ gate_callback (void*, void*)
287     // Parse the GCC tree to semantic graph.
288     //
289     parser p (*options_, loc_pragmas_, ns_loc_pragmas_, decl_pragmas_);
290-    auto_ptr<unit> u (p.parse (global_namespace, file_));
291+    unique_ptr<unit> u (p.parse (global_namespace, file_));
292
293     features f;
294
295@@ -377,14 +377,14 @@ plugin_init (plugin_name_args* plugin_info, plugin_gcc_version*)
296       oi[2].arg = &pd;
297
298       cli::argv_file_scanner scan (argc, &argv[0], oi, 3);
299-      auto_ptr<options> ops (
300+      unique_ptr<options> ops (
301         new options (scan, cli::unknown_mode::fail, cli::unknown_mode::fail));
302
303       // Process options.
304       //
305       process_options (*ops);
306
307-      options_ = ops;
308+      options_ = move (ops);
309       pragma_db_ = db;
310       pragma_multi_ = options_->multi_database ();
311     }
312diff --git a/odb/processor.cxx b/odb/processor.cxx
313index bea3624..c787e0d 100644
314--- a/odb/processor.cxx
315+++ b/odb/processor.cxx
316@@ -120,8 +120,8 @@ namespace
317       // both the wrapper type and the wrapped type must be const.
318       // To see why, consider these possibilities:
319       //
320-      // auto_ptr<const T> - can modify by setting a new pointer
321-      // const auto_ptr<T> - can modify by changing the pointed-to value
322+      // unique_ptr<const T> - can modify by setting a new pointer
323+      // const unique_ptr<T> - can modify by changing the pointed-to value
324       //
325       if (const_type (m.type ()) &&
326           !(id (m) || version (m) || m.count ("inverse")))
327@@ -3086,7 +3086,7 @@ process (options const& ops,
328 {
329   try
330   {
331-    auto_ptr<context> ctx (create_context (cerr, unit, ops, f, 0));
332+    unique_ptr<context> ctx (create_context (cerr, unit, ops, f, 0));
333
334     // Common processing.
335     //
336diff --git a/odb/validator.cxx b/odb/validator.cxx
337index aac52e4..196386c 100644
338--- a/odb/validator.cxx
339+++ b/odb/validator.cxx
340@@ -1516,7 +1516,7 @@ validate (options const& ops,
341   if (!valid)
342     throw validator_failed ();
343
344-  auto_ptr<context> ctx (create_context (cerr, u, ops, f, 0));
345+  unique_ptr<context> ctx (create_context (cerr, u, ops, f, 0));
346
347   if (pass == 1)
348   {
349--
3502.25.0
351
352