Problem with list initialization

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

In order for pgc++ to recognize c++11 or c++14 features, the
g++ version you installed under should also support c++11 and c++14.

Make sure g++ --version are 5.2 or newer. See PGI Release Notes
for this info.

% g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

% g++ -c test.cpp -std=c++11
works, and so does
% pgc++ -c test.cpp -std=c++11

on g++ 4.4.7 - things do not work.

with
% g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
% g++ -c test.cpp -std=c++11
cc1plus: error: unrecognized command line option “-std=c++11”
% pgc++ -c test.cpp -std=c++11
“test.cpp”, line 12: error: invalid type for defaulted constructor
ScalarCustomType(ScalarCustomType<T,rows,cols>&&) = default;
^

“test.cpp”, line 15: error: namespace “std” has no member “forward”
ScalarCustomType(Args&&… args) : data{std::forward(args)…} {}
^

“test.cpp”, line 15: error: type name is not allowed
ScalarCustomType(Args&&… args) : data{std::forward(args)…} {}
^

“test.cpp”, line 15: error: braces cannot be omitted for this subobject
initializer
ScalarCustomType(Args&&… args) : data{std::forward(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

4 errors detected in the compilation of “test.cpp”.

dave