Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
38 Views

Default constructor of variant is deleted ?

icpc (ICC) 19.0.0.117 20180804

This works in g++ but not icpc with the same runtime library includes.

icpc -std=c++17 -c /tmp/t.cpp -o /tmp/t.o

#include <variant>

void foo();
void foo()
{
  std::variant<std::monostate, int> bar;
}

Gives: 

/tmp/t.cpp(7): error: the default constructor of "std::variant<std::monostate, int>" cannot be referenced -- it is a deleted function
    std::variant<std::monostate, int> bar;


According to cppreference, the default constructor "Constructs a variant holding the
value-initialized value of the first alternative (index() is zero). This constructor 
is constexpr if and only if the value initialization of the alternative type T_0 would
satisfy the requirements for a constexpr function. This overload only participates in 
overload resolution if std::is_default_constructible_v<T_0> is true."
0 Kudos
4 Replies
Highlighted
Moderator
38 Views

Let me look into it and will get back to you.

Thanks,

Viet

0 Kudos
Highlighted
Moderator
38 Views

I have reported this to our Developer. Case number is CMPLRLIBS-2742

0 Kudos
Highlighted
Beginner
38 Views

I had a workaround, but now I get an internal compiler error in Update 1 (2019.1.144):

#include <variant>

int main()
{
  using var_t = std::variant<std::monostate, int>;
  struct Workaround : var_t
  {
    Workaround() : var_t(std::in_place_type<std::monostate>)
    {}
  };

  Workaround myvar;
  return 0;

}

/opt/intel/compilers_and_libraries_2019.1.144/linux/bin/intel64/icpc    -g   -std=gnu++17 -o CMakeFiles/tmpproject.dir/__/main.cpp.o -c /home/jharris/tmp/tmpproject/main.cpp
/home/jharris/tmp/tmpproject/main.cpp(10): internal error: assertion failed at: "shared/cfe/edgcpfe/class_decl.c", line 3662

      {}
      ^

0 Kudos
Highlighted
Moderator
38 Views

Thanks for reporting it. This seems to be a known issue. We have a bug number cmplril0-30500 to track it.

Viet

0 Kudos