Hi, I’m trying to compile some code written using some C+±14 features.
As an minimal example, consider this code “unique.cpp”:
#include <iostream>
#include <memory>
struct Vec3
{
int x, y, z;
Vec3() : x(0), y(0), z(0) { }
Vec3(int x, int y, int z) :x(x), y(y), z(z) { }
friend std::ostream& operator<<(std::ostream& os, Vec3& v) {
return os << '{' << "x:" << v.x << " y:" << v.y << " z:" << v.z << '}';
}
};
int main()
{
// Use the default constructor.
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
// Use the constructor that matches these arguments
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0, 1, 2);
// Create a unique_ptr to an array of 5 elements
std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
std::cout << "make_unique<Vec3>(): " << *v1 << '\n'
<< "make_unique<Vec3>(0,1,2): " << *v2 << '\n'
<< "make_unique<Vec3[]>(5): " << '\n';
for (int i = 0; i < 5; i++) {
std::cout << " " << v3[i] << '\n';
}
}
On our cluster, the PGI compilers are built against GCC 6.4, I believe. When I compile with g+±6.4
g++ unique.cpp
Compilation succeeds.
With pgc++ however, I see numerous failures.
pgc++ --c++14 unique.cpp
"unique.cpp", line 18: error: namespace "std" has no member "make_unique"
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
^
"unique.cpp", line 18: error: type name is not allowed
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
^
"unique.cpp", line 18: error: expected an expression
std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
^
"unique.cpp", line 20: error: namespace "std" has no member "make_unique"
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0, 1, 2);
^
"unique.cpp", line 20: error: type name is not allowed
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0, 1, 2);
^
"unique.cpp", line 20: warning: expression has no effect
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0, 1, 2);
^
"unique.cpp", line 20: warning: expression has no effect
std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0, 1, 2);
^
"unique.cpp", line 22: error: namespace "std" has no member "make_unique"
std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
^
"unique.cpp", line 22: error: type name is not allowed
std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
^
"unique.cpp", line 22: error: expected an expression
std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
^
8 errors detected in the compilation of "unique.cpp".
Should I expect to be able to compile this code with PGI C++? If so is the issue related to the GCC PGI links with?
Thanks,
Trevor