[Variant] Bug assigning similar, but different concrete types during assignment / ctor relay
Hello, I've got a Boost.Variant confusion going on during ctor relay. I have two types participating in the Variant, an Integer type and a Floating Point type. Both are Numeric as a base class. i.e. something like: template<typename T> struct numeric {}; struct integer : numeric<long> {}; struct floating_point : numeric<double> {}; Then: using constant_value = boost::variant<..., floating_point, integer, ...>; Somewhere during the handling, I have a test case in which I have a constant_value{} starting out in life as an integer{}. However, somewhere during handling, variant is misinterpreting integer (which=3) as a floating_point (which=2). This is incorrect, of course. I could force the issue, I suppose and re-set the value to the integer, but I'd like to understand the issue. I think it's a bug in variant, or perhaps a "feature" confusing integer with floating_point along base class numeric lines? Any ideas
Please disregard... The confusion is mine. I have two different levels
of AST going on, and two different Variants going on...
On Sun, Nov 18, 2018 at 6:00 PM Michael Powell
Hello,
I've got a Boost.Variant confusion going on during ctor relay.
I have two types participating in the Variant, an Integer type and a Floating Point type. Both are Numeric as a base class. i.e. something like:
template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
Then:
using constant_value = boost::variant<..., floating_point, integer, ...>;
Somewhere during the handling, I have a test case in which I have a constant_value{} starting out in life as an integer{}.
However, somewhere during handling, variant is misinterpreting integer (which=3) as a floating_point (which=2).
This is incorrect, of course.
I could force the issue, I suppose and re-set the value to the integer, but I'd like to understand the issue. I think it's a bug in variant, or perhaps a "feature" confusing integer with floating_point along base class numeric lines?
Any ideas
On Sun, Nov 18, 2018 at 6:09 PM Michael Powell
of AST going on, and two different Variants going on... On Sun, Nov 18, 2018 at 6:00 PM Michael Powell
wrote: Hello,
I've got a Boost.Variant confusion going on during ctor relay.
No, I take that back, I really do have some confusion going on in Variant. It wants to see my Integer type as a Floating Point, and the Which is indicating as much. When it comes time for me to use that later during a type trait driven string print, I get a bad_get exception because Which mis-reported the type.
I have two types participating in the Variant, an Integer type and a Floating Point type. Both are Numeric as a base class. i.e. something like:
template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
Then:
using constant_value = boost::variant<..., floating_point, integer, ...>;
Somewhere during the handling, I have a test case in which I have a constant_value{} starting out in life as an integer{}.
However, somewhere during handling, variant is misinterpreting integer (which=3) as a floating_point (which=2).
This is incorrect, of course.
I could force the issue, I suppose and re-set the value to the integer, but I'd like to understand the issue. I think it's a bug in variant, or perhaps a "feature" confusing integer with floating_point along base class numeric lines?
Any ideas
AMDG On 11/18/2018 04:00 PM, Michael Powell via Boost-users wrote:
I've got a Boost.Variant confusion going on during ctor relay.
I have two types participating in the Variant, an Integer type and a Floating Point type. Both are Numeric as a base class. i.e. something like:
template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
integer and floating_point are unrelated. I don't see any for for variant to get confused about them. Something like this could happen during assignment, if an exception is thrown. Variant assignment only provides the basic exception guarantee and may fall back on a no-throw default constructor of one of the bounded types.
Then:
using constant_value = boost::variant<..., floating_point, integer, ...>;
Somewhere during the handling, I have a test case in which I have a constant_value{} starting out in life as an integer{}.
However, somewhere during handling, variant is misinterpreting integer (which=3) as a floating_point (which=2).
So, the first `...` contains two types?
This is incorrect, of course.
I could force the issue, I suppose and re-set the value to the integer, but I'd like to understand the issue. I think it's a bug in variant, or perhaps a "feature" confusing integer with floating_point along base class numeric lines?
This code seems to work correctly:
#include
On Sun, Nov 18, 2018 at 6:22 PM Steven Watanabe via Boost-users
AMDG
On 11/18/2018 04:00 PM, Michael Powell via Boost-users wrote:
I've got a Boost.Variant confusion going on during ctor relay.
I have two types participating in the Variant, an Integer type and a Floating Point type. Both are Numeric as a base class. i.e. something like:
template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
integer and floating_point are unrelated. I don't see any for for variant to get confused about them.
Something like this could happen during assignment, if an exception is thrown. Variant assignment only provides the basic exception guarantee and may fall back on a no-throw default constructor of one of the bounded types.
Then:
using constant_value = boost::variant<..., floating_point, integer, ...>;
Somewhere during the handling, I have a test case in which I have a constant_value{} starting out in life as an integer{}.
However, somewhere during handling, variant is misinterpreting integer (which=3) as a floating_point (which=2).
So, the first `...` contains two types?
This is incorrect, of course.
I could force the issue, I suppose and re-set the value to the integer, but I'd like to understand the issue. I think it's a bug in variant, or perhaps a "feature" confusing integer with floating_point along base class numeric lines?
This code seems to work correctly:
#include
#include <iostream> template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
using constant_value = boost::variant
; int main() { constant_value x = integer{}; std::cout << x.which() << std::endl; std::cout << x.type().name() << std::endl; }
$ ./scratch 2 struct integer $
I'm trying to identify the issue. I am also passing them, or their hosts/containers around as reference parameters. Shouldn't make a difference, I think, since it is a reference? No relation? Other than the fact they are both numeric. I do not know why that would make a difference, but it seems to be.
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sun, Nov 18, 2018 at 6:33 PM Michael Powell
On Sun, Nov 18, 2018 at 6:22 PM Steven Watanabe via Boost-users
wrote: AMDG
On 11/18/2018 04:00 PM, Michael Powell via Boost-users wrote:
I've got a Boost.Variant confusion going on during ctor relay.
Identified. Typo in my which comprehension. I had Integer and FP backwards. :)
I have two types participating in the Variant, an Integer type and a Floating Point type. Both are Numeric as a base class. i.e. something like:
template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
integer and floating_point are unrelated. I don't see any for for variant to get confused about them.
Something like this could happen during assignment, if an exception is thrown. Variant assignment only provides the basic exception guarantee and may fall back on a no-throw default constructor of one of the bounded types.
Then:
using constant_value = boost::variant<..., floating_point, integer, ...>;
Somewhere during the handling, I have a test case in which I have a constant_value{} starting out in life as an integer{}.
However, somewhere during handling, variant is misinterpreting integer (which=3) as a floating_point (which=2).
So, the first `...` contains two types?
This is incorrect, of course.
I could force the issue, I suppose and re-set the value to the integer, but I'd like to understand the issue. I think it's a bug in variant, or perhaps a "feature" confusing integer with floating_point along base class numeric lines?
This code seems to work correctly:
#include
#include <iostream> template<typename T> struct numeric {};
struct integer : numeric<long> {};
struct floating_point : numeric<double> {};
using constant_value = boost::variant
; int main() { constant_value x = integer{}; std::cout << x.which() << std::endl; std::cout << x.type().name() << std::endl; }
$ ./scratch 2 struct integer $
I'm trying to identify the issue. I am also passing them, or their hosts/containers around as reference parameters. Shouldn't make a difference, I think, since it is a reference?
No relation? Other than the fact they are both numeric. I do not know why that would make a difference, but it seems to be.
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Michael Powell
-
Steven Watanabe