Dear all,
I encounter several problem when compiling the following code with PGI 2017 under macOS both with -std=c++11 and -std=c++14
#include <iostream>
template<typename T, int rows, int cols>
struct ScalarCustomType
{
T data[rows][cols];
ScalarCustomType() = default;
ScalarCustomType(const ScalarCustomType<T,rows,cols>&) = default;
ScalarCustomType(ScalarCustomType<T,rows,cols>&) = default;
ScalarCustomType(ScalarCustomType<T,rows,cols>&&) = default;
template<typename ...Args>
ScalarCustomType(Args&&... args) : data{std::forward<Args>(args)...} {}
friend std::ostream& operator<< (std::ostream& stream, const ScalarCustomType<T,rows,cols>& obj) {
stream << "[";
for (int i=0; i<rows; i++) {
for (int j=0; j<cols; j++) {
stream << obj.data[i][j] << (j==cols-1 ? (i==rows-1 ? "" : ";") : ",");
}
}
stream << "]";
return stream;
}
};
int main()
{
ScalarCustomType<int,3,3> A{1,2,3,4,5,6,7,8,9}, B{A};
std::cout << A << std::endl;
std::cout << B << std::endl;
return 0;
}
Firstly, the line
ScalarCustomType(ScalarCustomType<T,rows,cols>&&) = default;
is considered invalid
line 12: error: invalid type for defaulted constructor
ScalarCustomType(ScalarCustomType<T,rows,cols>&&) = default;
This does not happen with any version of g++ and clang++.
Secondly, when I comment this line the compiler complains about
line 15: error: braces cannot be omitted for this subobject
initializer
ScalarCustomType(Args&&... args) : data{std::forward<Args>(args)...} {}
^
detected during instantiation of "ScalarCustomType<T, rows,
cols>::ScalarCustomType(Args &&...) [with T=int, rows=3,
cols=3, Args=<int, int, int, int, int, int, int, int,
int>]" at line 31
Can you confirm that this is a bug of the compiler or in my code?
Kind regards,
Matthias