Nvc++ fails to compile mutable member access

I have the following piece of code which fails to compile on nvc++:

I tested all versions of nvc++ on compiler explorer and on our own machine with:
gcc-toolchain: gcc-11.3
cuda:11-8
hpc sdk: 24.1

The code has only host operations and is used in a header I need to include in a file compiled with nvc++. With clang and gcc the code compiles fine. Is there someting wrong with the code or is nvc++ missing some feature?

Hi petteri.peltonen!

We reached out to our expert C++ compiler engineer and apparently he’s already addressed the issue on discord with either you - or someone on your team working on the same issue. However, for clarity, I will copy his response to the issue here:

It’s a bug in nvc++. The bug happens when the assignment is inside a template, the left-hand side of the assignment is accessing a field, the left-hand side of the . is a function call that returns an lvalue, and the right-hand side of the . is a qualified name. Here is a minimal example.
template T& noop(T& x) { return x; }
template struct A {
int z;
void f() {
noop(*this).A::z = 42;
}
};
int main() {
A a;
a.f();
}
You can work around the bug in your example code by getting rid of the qualified name, e.g. field_.ref().index_ = 54;, or by avoiding the lvalue return value, such as (&field_.ref())->Holder::index_ = 54;. I suspect the second option will work better in the original code.

My understanding is the engineer asked you/your team to open a nvbug report on it - or to notify him if he needs to open it. So hopefully the bug gets into the queue and can be resolved in a future release on NVHPC!

Thank you for bringing this to our attention. We will work to get it resolved!