I am getting a compiler error when I am trying to compile with specific compiler version.
ie. icc 17.0 with -std=c++17 -O3
Compiler Error:
source>(19): error: no suitable user-defined conversion from "Data" to "std::__cxx11::string" exists
Data temp{std::forward<Data>(d)};
^
compilation aborted for <source> (code 2)
ASM generation compiler returned: 2
<source>(19): error: no suitable user-defined conversion from "Data" to "std::__cxx11::string" exists
Data temp{std::forward<Data>(d)};
^
compilation aborted for <source> (code 2)
Execution build compiler returned: 2
Code:
#include <string>
#include <vector>
#include <iostream>
struct Data {
std::string id{};
std::string rowData{};
int totalRawDataLength{};
std::vector<int> rawDataOffset{};
std::vector<int> rawDataLength{};
Data() = default;
Data(const Data&d) =default;
Data(Data &&d) =default;
};
Data ProcessData(Data &&d) {
Data temp{std::forward<Data>(d)};
// some code
return temp;
}
int main() {
Data d{};
d.id = "id_001";
d.rowData = "some data";
d.rawDataOffset.emplace_back(4);
d.rawDataLength.emplace_back(4);
auto x = ProcessData(std::move(d));
std::cout << "Test:" << x.id << std::endl;
return 0;
}
following code works for all version of gcc and it works with the higher version of icc with same compiler options.
it even works for -std=c++11 -O3 for icc 17.0
on further debugging found out that something is wrong with default copy constructor which is being generated.
I am not able to understand what's wrong happening hear is it some kind of compiler bug which got resolved in later releases?