Discussion:
Incorrect variant behavior
(too old to reply)
a***@gmail.com
2018-10-28 08:46:47 UTC
Permalink
I believe that std::variant behaves incorreclty in following scenario:

struct some_user_type
{
CString field;
};
std::variant<
some_user_type,
CString
variant_;
//Somewhere in the code in two different places
//Place 1
CString cstr{L"CString"};
variant_ = cstr;

//Place 2
some_user_type ut{L"some_user_type"};
variant_ = some_user_type;

//Later on in yet different place in code
//Now depending on what got assigned either place 1 or place 2 this code
should fail, fail in a sense that nullptr will be returned from get_if, if
place 1 was assigned:

const some_user_type* const ut = std::get_if<some_user_type
(&variant_);
/*But it doesn't and I believe that this is incorrect, faulty behavior*/




Looking forward to replies.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...