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 23:07:21


#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 t0rt1e@…):

 Thank you very much Seth and Hartmut for finally tracking down the root of
 the problem! It's good to know that we are facing undefined behavior
 instead of a compiler bug.

 Replying to [comment:17 hkaiser]:
> Replying to [comment:16 Seth Heeren <bugs@…>]:
> > Replying to [comment:15 hkaiser]:
> > >
> > > That's excellent news! Thanks. That allows to revert the patch
 above.
> >
> > Do you have ideas on how to fix it? My suggestion for the OP is
 really a workaround:
> >
> > * bug: ADT accessors returning by value leads to UB
> > * workaround: don't do that, then?
> >
> > The docs clearly suggest that returning by value from the accessors is
 `ok` practice (and that adds value, IMO). However, the code appears to
 have the assumption that attributes can always be fully 'resolved' to a
 reference.

 I second Seth's opinion that supporting ADTs, which getters return by
 value gives added value. In my case, I cannot simply change the return
 type in the signature of the getters. The original test case
 {{{test_signed_integer_output_with_karma}}} I provided is close to my
 production code, where I adapted {{{boost::rational<long>}}} for usage in
 Spirit and Karma rules. Its implementation returns the numerator and
 denominator by value.

> The docs are Fusion related. There it is possible and valid to do such
 things. The problem is that Karma (falsely) assumes this as well.

 Well, at least till Boost 1.48.0, the Karma tutorial demonstrates adapting
 {{{std::complex<double>}}} for usage with Karma, which {{{real()}}} and
 {{{imag()}}} member functions also return by value.

> > Apart from specializing extract_from_attribute for adt_attribute_proxy
 I don't see an easy way to resolve this. And I wouldn't think that this
 approach is entirely trivial, either (it might be enough due to the
 implicit conversion of the proxy to its exposed type?)
>
> Yep, that's what I think needs to be done, at least as a first step.

 Could you maybe provide some more instructions how to specialize correctly
 {{{adt_attribute_proxy}}} for {{{std::rational<long>}}} or
 {{{std::complex<double>}}}? I think such kind of explanation and some
 pitfall notes would be very helpful in the Spirit.Karma documentation. I
 have not yet had the time to actually try myself specializing
 {{{adt_attribute_proxy}}}, but hope it won't be more effort than
 implementing my own rational class.

 It would be nice if this issue could be resolved in the long term in a
 more user-friendly way.

 Thank you very much for your help!

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6126#comment:18>
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