From fc03b894489f39c81f69cd789fd9a08aa5acf91b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Jan 2020 14:17:22 +0200 Subject: Fix ability to handle C-style arrays as containers --- odb/context.cxx | 8 +++++--- odb/context.hxx | 12 ++++++++---- odb/relational/source.hxx | 9 +++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) (limited to 'odb') diff --git a/odb/context.cxx b/odb/context.cxx index 4daa896..1e5c6c2 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -1493,15 +1493,17 @@ string context:: type_ref_type (semantics::type& t, semantics::names* hint, bool mc, - string const& var) + string const& var, + bool decay) { using semantics::array; string r; // Note that trailing const syntax is used for a reason (consider - // t == const foo*). We also have to decay top-level arrays. + // t == const foo*). We may also have to decay then top-level array. // - if (array* a = dynamic_cast (&utype (t))) + array* a; + if (decay && (a = dynamic_cast (&utype (t))) != 0) { semantics::type& bt (a->base_type ()); hint = a->contains ().hint (); diff --git a/odb/context.hxx b/odb/context.hxx index f9203ae..4366fb7 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -714,21 +714,25 @@ public: // make_const is true, then add top-level const qualifier, unless // it is already there. If it is false, then strip it if it is // already there. If var is not empty, then embed the variable - // name into the type (e.g., char (*v)[3]). + // name into the type (e.g., char (*v)[3]). If decay_array is + // false then don't decay the (top-level) array to a pointer. // static string member_ref_type (semantics::data_member& m, bool make_const, - string const& var = "") + string const& var = "", + bool decay_array = true) { - return type_ref_type (m.type (), m.belongs ().hint (), make_const, var); + return type_ref_type ( + m.type (), m.belongs ().hint (), make_const, var, decay_array); } static string type_ref_type (semantics::type&, semantics::names* hint, bool make_const, - string const& var = ""); + string const& var = "", + bool decay_array = true); // Form a value type for a not mapped, actual member type. If make_const // is true, then add top-level const qualifier, unless it is already diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx index 681323a..e986cd8 100644 --- a/odb/relational/source.hxx +++ b/odb/relational/source.hxx @@ -5327,9 +5327,14 @@ namespace relational if (!ma.synthesized) os << "// From " << location_string (ma.loc, true) << endl; + // Note that here we don't decay arrays. + // + const string& ref_type ( + member_ref_type (m, call_ != load_call, "v", false /* decay */)); + // VC++ cannot grok the constructor syntax. // - os << member_ref_type (m, call_ != load_call, "v") << " =" << endl + os << ref_type << " =" << endl << " "; // If this member is const and we have a synthesized direct @@ -5338,7 +5343,7 @@ namespace relational // bool cast (call_ == load_call && ma.direct () && const_member (m)); if (cast) - os << "const_cast< " << member_ref_type (m, false) << + os << "const_cast< " << member_ref_type (m, false, "", false) << " > (" << endl; os << ma.translate (obj_prefix_); -- cgit v1.1