0007-Switch-to-C-11-get-rid-of-auto_ptr-use.patch 12 KB

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