From 6e374de9ae2f2978f2fca3390aba4ea3f72bfade Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Nov 2017 10:37:53 +0200 Subject: Switch to C++11, get rid of auto_ptr use --- odb/Makefile.am | 5 +++++ odb/context.cxx | 4 ++-- odb/context.hxx | 4 ++-- odb/generator.cxx | 18 +++++++++--------- odb/makefile | 8 +++++++- odb/options.cli | 4 ++-- odb/parser.cxx | 14 ++++++++++---- odb/parser.hxx | 7 ++++--- odb/plugin.cxx | 10 +++++----- odb/processor.cxx | 6 +++--- odb/validator.cxx | 2 +- 11 files changed, 50 insertions(+), 32 deletions(-) diff --git a/odb/Makefile.am b/odb/Makefile.am index a8d3ba3..c0d4ce1 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 = __path__(headers) __path__(extra_dist) # Plugin. diff --git a/odb/context.cxx b/odb/context.cxx index 0ca39a8..7801072 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -796,14 +796,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 7c983fc..103646d 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 @@ -1899,7 +1899,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 74de7d1..bb8e12f 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 @@ -166,7 +166,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) { @@ -496,7 +496,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); @@ -606,7 +606,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); @@ -666,7 +666,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); @@ -759,7 +759,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); @@ -824,7 +824,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) @@ -890,7 +890,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) { @@ -933,7 +933,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/makefile b/odb/makefile index 5a67fec..cd952f6 100644 --- a/odb/makefile +++ b/odb/makefile @@ -294,7 +294,13 @@ $(call include,$(bld_root)/cxx/o-e.make) # ifdef cxx_gnu -$(cxx_pobj) $(cxx_cobj): cxx_pic_options := -fPIC +$(odb) $(odb_so) \ +$(cxx_pobj) $(cxx_pod) \ +$(cxx_cobj) $(cxx_cod) \ +$(cxx_dobj) $(cxx_dod): cxx_extra_options += -std=c++0x + +$(cxx_pobj) $(cxx_pod) \ +$(cxx_cobj) $(cxx_cod): cxx_pic_options := -fPIC $(cxx_cobj) $(cxx_cod): cpp_options := -I$(src_root) $(cxx_dobj) $(cxx_dod): cpp_options := -I$(src_root) '-DODB_GXX_NAME="$(cxx_gnu)"' diff --git a/odb/options.cli b/odb/options.cli index e9ed272..1209177 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 00483cd..79a5bc2 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: @@ -750,10 +750,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); @@ -2265,6 +2265,12 @@ fq_scope (tree decl) // parser:: +~parser () +{ + // Needs parser::impl definition. +} + +parser:: parser (options const& ops, loc_pragmas& lp, ns_loc_pragmas& nslp, @@ -2273,7 +2279,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 97b138c..d8fd60f 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 6c78d11..c046c2f 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; @@ -381,14 +381,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 1e6557f..7c396e7 100644 --- a/odb/processor.cxx +++ b/odb/processor.cxx @@ -140,8 +140,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_member (m) && !(id (m) || version (m) || m.count ("inverse"))) { @@ -3148,7 +3148,7 @@ process1 (semantics::unit& u) static void process2 (options const& ops, features& f, semantics::unit& u) { - auto_ptr ctx (create_context (cerr, u, ops, f, 0)); + unique_ptr ctx (create_context (cerr, u, ops, f, 0)); // Common processing. // diff --git a/odb/validator.cxx b/odb/validator.cxx index 6ba5efb..0c95d0f 100644 --- a/odb/validator.cxx +++ b/odb/validator.cxx @@ -1816,7 +1816,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) { -- cgit v1.1