Search code examples
c++c++11default-valuemove-semanticsicc

what's the correct default value for an r-value reference argument?


Suppose I have a function that takes an r-value argument and I want to provide a default value, how do I correctly specify that? The following works fine with gcc 4.7.0, but fails with icpc 13.0.1.

struct data {
  int _data[10];
  data() = default;
  data(data&&) = default;
  data(const data&) = default;
};
void func(data&& = data{});

icpc complains that

error: type name is not allowed
void func(data&& = data{});
                   ^

Is this correct? What is the correct syntax?


Solution

  • It appears that icpc 13.0.1 doesn't support universal-initialization syntax in default arguments. This works:

    void func(data&& = data());
                           ^^ value-initialization