Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Variant: Infinite recursion in constructor
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-09-06 10:19:36


AMDG

On 09/06/2012 12:29 AM, Markus Lenger wrote:
> Hi!
>
> I face a problem using Boost.Variant 1.48 under Windows with Cygwin
> and g++ (GCC) 4.5.3. The following code crashes due to infinite
> recursion in the constructor of a_t:
>
> #include <boost/variant.hpp>
> #include <iostream>
>
> struct a_t
> {
> boost::variant< boost::recursive_wrapper<a_t>,int > child;
> };
>
> int main()
> {
> a_t a;
> std::cout << "OK" << std::endl;
> return 0;
> }
>
> If I change the type of "child" to "boost::variant< int,
> boost::recursive_wrapper<a_t> >" (I just swapped the template
> parameters) the program prints "OK".
>
> Any ideas?
>

A default constructed variant contains a default
constructed instance of the first variant type.
Swapping the template parameters causes it to
hold an int instead of recursively constructing
an a_t.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net