Boost.Spirit.Qi and Boost.Variant doesn't work together with NDEBUG on clang or gcc

Damien Buhl <[email protected]> Wed, 14 Sep 2016 10:37:34 +0200
Newsgroups gmane.comp.parsers.spirit.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============8321797091182033213==
Content-Type: multipart/alternative;
	boundary="------------74892477CDDB948E6BE28FD7"

This is a multi-part message in MIME format.
--------------74892477CDDB948E6BE28FD7
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Hi Spirit developers ,

I've found an issue in Boost.Spirit.Qi when parsing a Variant with the
bitwise-or operator, if I add the compile flag -DNDEBUG, a simple qi
rule is not able to initialize a variant anymore with the parsed data.

I don't know if this issue already exists, I searched on the trac but
couldn't find anything.

> typedef boost::variant<int, bool, std::string> frame;
>
>   rule<Iterator, frame()> r =
>       int_
>     | bool_
>     | as_string[*char_]
>   ;

The code to reproduce the bug is here :
https://github.com/daminetreg/bug-boost-spirit-qi-ndebug/blob/master/ndebug_compilation.cpp

If I parse the texts, in order :  "this is a string", "42", "true", then
I get :

Compiled*without -DNDEBUG,* it parses correctly :
http://melpon.org/wandbox/permlink/y3ueDkxbJYsYn7vs

> $ ./without_ndebug
> NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE this is a string
> i 42
> b 1

Once compiled *with -DNDEBUG*, it doesn't parse anything anymore and let
the variant default-initialized:
http://melpon.org/wandbox/permlink/cgu20wphStlrJoMQ

> $ ./with_ndebug
> i 0
> i 0
> i 0

I can confirm the bug is not in Boost.Variant but somewhere else,
because I can reproduce it exactly, using another Variant type (i.e.
MapBox.Variant) : https://github.com/sauter-hq/boost-spirit-mapbox-variant.

I think it's not compiler related, because different versions of clang
and gcc appears to produce the same result.

Cheers,

--
Damien Buhl


--------------74892477CDDB948E6BE28FD7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by smtp-sh.infomaniak.ch
	id u8E8bZTF031994

<html>
  <head>

    <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf=
-8">
  </head>
  <body text=3D"#000000" bgcolor=3D"#FFFFFF">
    <p>Hi Spirit developers ,</p>
    <p>I've found an issue in Boost.Spirit.Qi when parsing a Variant
      with the bitwise-or operator, if I add the compile flag -DNDEBUG,
      a simple qi rule is not able to initialize a variant anymore with
      the parsed data.<br>
    </p>
    <p>I don't know if this issue already exists, I searched on the trac
      but couldn't find anything.<br>
    </p>
    <p>
      <blockquote type=3D"cite">typedef boost::variant&lt;int, bool,
        std::string&gt; frame;<br>
        <br>
        =C2=A0 rule&lt;Iterator, frame()&gt; r =3D <br>
        =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int_<br>
        =C2=A0=C2=A0=C2=A0 | bool_<br>
        =C2=A0=C2=A0=C2=A0 | as_string[*char_]<br>
        =C2=A0 ;</blockquote>
    </p>
    <p>The code to reproduce the bug is here :
<a class=3D"moz-txt-link-freetext" href=3D"https://github.com/daminetreg/=
bug-boost-spirit-qi-ndebug/blob/master/ndebug_compilation.cpp">https://gi=
thub.com/daminetreg/bug-boost-spirit-qi-ndebug/blob/master/ndebug_compila=
tion.cpp</a></p>
    <p>If I parse the texts, in order :=C2=A0 "this is a string", "42",
      "true", then I get : <br>
    </p>
    <p>Compiled<b> without -DNDEBUG,</b> it parses correctly : <br>
      <a class=3D"moz-txt-link-freetext" href=3D"http://melpon.org/wandbo=
x/permlink/y3ueDkxbJYsYn7vs">http://melpon.org/wandbox/permlink/y3ueDkxbJ=
YsYn7vs</a><br>
      <blockquote type=3D"cite">$ ./without_ndebug <br>
        NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE this is a
        string<br>
        i 42<br>
        b 1<br>
      </blockquote>
    </p>
    <p>Once compiled <b>with -DNDEBUG</b>, it doesn't parse anything
      anymore and let the variant default-initialized: <br>
      <a class=3D"moz-txt-link-freetext" href=3D"http://melpon.org/wandbo=
x/permlink/cgu20wphStlrJoMQ">http://melpon.org/wandbox/permlink/cgu20wphS=
tlrJoMQ</a><br>
    </p>
    <blockquote type=3D"cite">$ ./with_ndebug <br>
      i 0<br>
      i 0<br>
      i 0</blockquote>
    <br>
    I can confirm the bug is not in Boost.Variant but somewhere else,
    because I can reproduce it exactly, using another Variant type (i.e.
    MapBox.Variant) :
    <a class=3D"moz-txt-link-freetext" href=3D"https://github.com/sauter-=
hq/boost-spirit-mapbox-variant">https://github.com/sauter-hq/boost-spirit=
-mapbox-variant</a>.<br>
    <br>
    I think it's not compiler related, because different versions of
    clang and gcc appears to produce the same result.<br>
    <br>
    Cheers,
    <pre class=3D"moz-signature" cols=3D"72">--
Damien Buhl</pre>
  </body>
</html>

--------------74892477CDDB948E6BE28FD7--


--===============8321797091182033213==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============8321797091182033213==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Spirit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-devel

--===============8321797091182033213==--