On 2020-10-28 13:56, Nicolai G. via Gcc-help wrote:
Hi,
hi,
look at this:
https://en.cppreference.com/w/cpp/utility/variant/monostate
I've recently switched to GCC 9.3 (the same error on 10.2) and have a
compile issue.
The reproduction is the following:
--------------------------------------
#include <variant>
#include <string>
#include <vector>
struct response_t
{
struct response_a_t
{
std::string raw_data{};
};
struct response_b_t {};
std::variant< response_a_t, response_b_t > resp{};
};
void handle( response_t & r );
response_t test()
{
response_t r;
handle( r );
return r;
}
--------------------------------------
<source>:18:53: error: use of deleted function
'std::variant<_Types>::variant() [with _Types =
{response_t::response_a_t,
response_t::response_b_t}]'
13 | std::variant< response_a_t, response_b_t > resp{};
| ^
In file included from <source>:3:
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/variant:1347:7:
note:
'std::variant<_Types>::variant() [with _Types =
{response_t::response_a_t,
response_t::response_b_t}]' is implicitly deleted because the default
definition would be ill-formed:
1347 | variant() = default;
| ^~~~~~~
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/variant:1347:7:
error:
use of deleted function 'constexpr
std::_Enable_default_constructor<false,
_Tag>::_Enable_default_constructor() [with _Tag =
std::variant<response_t::response_a_t, response_t::response_b_t>]'
In file included from
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/variant:38,
from <source>:3:
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/bits/enable_special_members.h:110:15:
note: declared here
110 | constexpr _Enable_default_constructor() noexcept = delete;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 1
--------------------------------------
It worked on 8.3. And I don't see anything wrong with this snippet.
if *response_a_t* and *response_b_t* are not nested, then compilation
goes
fine.
Compilation is also ok if I put
*response_a_t the following way:*
struct response_a_t
{
std::string raw_data; // no {}
};
Reproduction on compile explorer: https://godbolt.org/z/ETzsqo
Can you, please, clarify on the subject?