Re: [Boost-bugs] [Boost C++ Libraries] #6126: Signed integer members of Boost.Fusion adapted ADTs are not output correctly with Boost.Spirit.Karma rules

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6126: Signed integer members of Boost.Fusion adapted ADTs are not output correctly with Boost.Spirit.Karma rules
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-02-02 01:14:58


#6126: Signed integer members of Boost.Fusion adapted ADTs are not output
correctly with Boost.Spirit.Karma rules
-------------------------------+--------------------------------------------
  Reporter: t0rt1e@… | Owner: hkaiser
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: spirit
   Version: Boost 1.48.0 | Severity: Regression
Resolution: | Keywords: patch proposed, Boost.Spirit.Karma, Boost.Fusion, BOOST_FUSION_ADAPT_CLASS, BOOST_FUSION_ADAPT_ADT, short, int, long
-------------------------------+--------------------------------------------

Comment (by hkaiser):

 Replying to [comment:13 bugs@…]:
> I tracked it down to
 extract_from_attribute<>::call<>(attr,ctx,true_type). It will generate an
 inner typedef of
>
> typedef typename mpl::eval_if<
> is_one_element_sequence
> , detail::value_at_c<Attribute, 0>
> , mpl::identity<Attribute const&>
> >::type type;
>
> which is going to be a reference. This is ok for tuples, adapted structs
 (typical fusion sequences) but not for ADT's as the accessor function
 returns a `short`, which **can** be bound to a const& **but** only locally
 (its lifetime won't be extended outside the scope in which the reference
 is declared).
>
> Now the way I see it in the code, the sample from the docs[1] `(int,
 int, obj.get_age(), obj.set_age(val))` won't work without undefined
 behaviour, precisely because it results in
 `extract_from_attribute<>::call<>` returning a reference to a local (`int`
 in that case).
>
> For the OP, I guess the best way to fix it would be to make the
 accessors return (const) references: (see attached)
>
> struct XR
> {
> short x;
>
> explicit XR(short num = 0) : x(num) {}
> const short& getx() const { return x; }
> short& getx() { return x; }
> void setx(short v) { x = v; }
> };
>
> BOOST_FUSION_ADAPT_ADT(XR, (short&, const short&, obj.getx(),
 obj.setx(val)))
>
> This also removed all the other valgrind messages that were previously
 unaccounted for.
>
> [1]
 http://www.boost.org/doc/libs/1_48_0/libs/fusion/doc/html/fusion/adapted/adapt_adt.html

 That's excellent news! Thanks. That allows to revert the patch above.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6126#comment:15>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:08 UTC