Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Default constructor of variant is deleted ?

$
0
0
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."

Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>