From c5bea9562929c6b55ca208a530ae80033eeb1614 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Nov 2017 10:37:53 +0200 Subject: [PATCH] Switch to C++11, get rid of auto_ptr use [Upstream: 6e374de9ae2f2978f2fca3390aba4ea3f72bfade] Signed-off-by: Kamel Bouhara --- odb/Makefile.am | 5 +++++ odb/context.cxx | 4 ++-- odb/context.hxx | 4 ++-- odb/generator.cxx | 18 +++++++++--------- odb/options.cli | 4 ++-- odb/parser.cxx | 14 ++++++++++---- odb/parser.hxx | 7 ++++--- odb/plugin.cxx | 10 +++++----- odb/processor.cxx | 6 +++--- odb/validator.cxx | 2 +- 10 files changed, 43 insertions(+), 31 deletions(-) diff --git a/odb/Makefile.am b/odb/Makefile.am index 2f01398..d9e83d7 100644 --- a/odb/Makefile.am +++ b/odb/Makefile.am @@ -9,6 +9,11 @@ plugin_LTLIBRARIES = odb.la AM_CPPFLAGS = -I'$(top_builddir)' -I'$(top_srcdir)' +# Note: not passed by libtool when linking odb.so. Seems to be harmless for +# now. +# +AM_CXXFLAGS = -std=c++0x + 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 # Plugin. diff --git a/odb/context.cxx b/odb/context.cxx index d62fa88..87f1c32 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -564,14 +564,14 @@ namespace }; } -auto_ptr +unique_ptr create_context (ostream& os, semantics::unit& unit, options const& ops, features& f, semantics::relational::model* m) { - auto_ptr r; + unique_ptr r; switch (ops.database ()[0]) { diff --git a/odb/context.hxx b/odb/context.hxx index 351bc61..10de237 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -13,7 +13,7 @@ #include #include #include -#include // std::auto_ptr +#include // std::unique_ptr #include #include // std::size_t #include @@ -1691,7 +1691,7 @@ private: // Create concrete database context. // -std::auto_ptr +std::unique_ptr create_context (std::ostream&, semantics::unit&, options const&, diff --git a/odb/generator.cxx b/odb/generator.cxx index 6aa5151..266b75f 100644 --- a/odb/generator.cxx +++ b/odb/generator.cxx @@ -4,7 +4,7 @@ #include // std::toupper, std::is{alpha,upper,lower} #include -#include // std::auto_ptr +#include // std::unique_ptr #include #include #include @@ -141,7 +141,7 @@ generate (options const& ops, if (gen_schema) { - auto_ptr ctx (create_context (cerr, unit, ops, fts, 0)); + unique_ptr ctx (create_context (cerr, unit, ops, fts, 0)); switch (db) { @@ -471,7 +471,7 @@ generate (options const& ops, // if (gen_cxx) { - auto_ptr ctx ( + unique_ptr ctx ( create_context (hxx, unit, ops, fts, model.get ())); sloc_filter sloc (ctx->os); @@ -581,7 +581,7 @@ generate (options const& ops, // if (gen_cxx) { - auto_ptr ctx ( + unique_ptr ctx ( create_context (ixx, unit, ops, fts, model.get ())); sloc_filter sloc (ctx->os); @@ -641,7 +641,7 @@ generate (options const& ops, // if (gen_cxx && (db != database::common || md == multi_database::dynamic)) { - auto_ptr ctx ( + unique_ptr ctx ( create_context (cxx, unit, ops, fts, model.get ())); sloc_filter sloc (ctx->os); @@ -734,7 +734,7 @@ generate (options const& ops, // if (gen_sep_schema) { - auto_ptr ctx ( + unique_ptr ctx ( create_context (sch, unit, ops, fts, model.get ())); sloc_filter sloc (ctx->os); @@ -799,7 +799,7 @@ generate (options const& ops, // if (gen_sql_schema) { - auto_ptr ctx ( + unique_ptr ctx ( create_context (sql, unit, ops, fts, model.get ())); switch (db) @@ -865,7 +865,7 @@ generate (options const& ops, // { ofstream& mig (*mig_pre[i]); - auto_ptr ctx (create_context (mig, unit, ops, fts, 0)); + unique_ptr ctx (create_context (mig, unit, ops, fts, 0)); switch (db) { @@ -908,7 +908,7 @@ generate (options const& ops, // { ofstream& mig (*mig_post[i]); - auto_ptr ctx (create_context (mig, unit, ops, fts, 0)); + unique_ptr ctx (create_context (mig, unit, ops, fts, 0)); switch (db) { diff --git a/odb/options.cli b/odb/options.cli index cf278cb..c994975 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -211,10 +211,10 @@ class options \cb{db pointer} pragma will use this pointer by default. The value of this option can be \cb{*} which denotes the raw pointer and is the default, or qualified name of a smart pointer class template, - for example, \cb{std::auto_ptr}. In the latter case, the ODB compiler + for example, \cb{std::shared_ptr}. In the latter case, the ODB compiler constructs the object or view pointer by adding a single template argument of the object or view type to the qualified name, for example - \cb{std::auto_ptr}. The ODB runtime uses object and view + \cb{std::shared_ptr}. The ODB runtime uses object and view pointers to return, and, in case of objects, pass and cache dynamically allocated instances of object and view types. diff --git a/odb/parser.cxx b/odb/parser.cxx index 927063b..30e45af 100644 --- a/odb/parser.cxx +++ b/odb/parser.cxx @@ -26,7 +26,7 @@ public: impl (options const&, loc_pragmas&, ns_loc_pragmas&, decl_pragmas&); - auto_ptr + unique_ptr parse (tree global_scope, path const& main_file); private: @@ -728,10 +728,10 @@ impl (options const& ops, { } -auto_ptr parser::impl:: +unique_ptr parser::impl:: parse (tree global_scope, path const& main_file) { - auto_ptr u (new unit (main_file)); + unique_ptr u (new unit (main_file)); u->insert (global_namespace, *u); process_named_pragmas (global_namespace, *u); @@ -2263,6 +2263,12 @@ fq_scope (tree decl) // parser // +parser:: +~parser () +{ + // Needs parser::impl definition. +} + parser:: parser (options const& ops, loc_pragmas& lp, @@ -2272,7 +2278,7 @@ parser (options const& ops, { } -auto_ptr parser:: +unique_ptr parser:: parse (tree global_scope, path const& main_file) { return impl_->parse (global_scope, main_file); diff --git a/odb/parser.hxx b/odb/parser.hxx index 80e4aa4..648337f 100644 --- a/odb/parser.hxx +++ b/odb/parser.hxx @@ -7,7 +7,7 @@ #include -#include // std::auto_ptr +#include // std::unique_ptr #include #include @@ -18,9 +18,10 @@ class parser public: class failed {}; + ~parser (); parser (options const&, loc_pragmas&, ns_loc_pragmas&, decl_pragmas&); - std::auto_ptr + std::unique_ptr parse (tree global_scope, semantics::path const& main_file); private: @@ -31,7 +32,7 @@ private: private: class impl; - std::auto_ptr impl_; + std::unique_ptr impl_; }; #endif // ODB_PARSER_HXX diff --git a/odb/plugin.cxx b/odb/plugin.cxx index 779faed..0fac632 100644 --- a/odb/plugin.cxx +++ b/odb/plugin.cxx @@ -8,7 +8,7 @@ #include // stat #include // stat -#include // std::auto_ptr +#include // std::unique_ptr #include #include #include // std::strcpy, std::strstr @@ -39,7 +39,7 @@ using cutl::fs::invalid_path; typedef vector paths; int plugin_is_GPL_compatible; -auto_ptr options_; +unique_ptr options_; paths profile_paths_; path file_; // File being compiled. paths inputs_; // List of input files in at-once mode or just file_. @@ -222,7 +222,7 @@ gate_callback (void*, void*) // Parse the GCC tree to semantic graph. // parser p (*options_, loc_pragmas_, ns_loc_pragmas_, decl_pragmas_); - auto_ptr u (p.parse (global_namespace, file_)); + unique_ptr u (p.parse (global_namespace, file_)); features f; @@ -377,14 +377,14 @@ plugin_init (plugin_name_args* plugin_info, plugin_gcc_version*) oi[2].arg = &pd; cli::argv_file_scanner scan (argc, &argv[0], oi, 3); - auto_ptr ops ( + unique_ptr ops ( new options (scan, cli::unknown_mode::fail, cli::unknown_mode::fail)); // Process options. // process_options (*ops); - options_ = ops; + options_ = move (ops); pragma_db_ = db; pragma_multi_ = options_->multi_database (); } diff --git a/odb/processor.cxx b/odb/processor.cxx index bea3624..c787e0d 100644 --- a/odb/processor.cxx +++ b/odb/processor.cxx @@ -120,8 +120,8 @@ namespace // both the wrapper type and the wrapped type must be const. // To see why, consider these possibilities: // - // auto_ptr - can modify by setting a new pointer - // const auto_ptr - can modify by changing the pointed-to value + // unique_ptr - can modify by setting a new pointer + // const unique_ptr - can modify by changing the pointed-to value // if (const_type (m.type ()) && !(id (m) || version (m) || m.count ("inverse"))) @@ -3086,7 +3086,7 @@ process (options const& ops, { try { - auto_ptr ctx (create_context (cerr, unit, ops, f, 0)); + unique_ptr ctx (create_context (cerr, unit, ops, f, 0)); // Common processing. // diff --git a/odb/validator.cxx b/odb/validator.cxx index aac52e4..196386c 100644 --- a/odb/validator.cxx +++ b/odb/validator.cxx @@ -1516,7 +1516,7 @@ validate (options const& ops, if (!valid) throw validator_failed (); - auto_ptr ctx (create_context (cerr, u, ops, f, 0)); + unique_ptr ctx (create_context (cerr, u, ops, f, 0)); if (pass == 1) { -- 2.25.0