hcc icon indicating copy to clipboard operation
hcc copied to clipboard

C++ class constructor not being called in some cases

Open misos1 opened this issue 7 years ago • 1 comments

In this example on host side cpu constructor of Inner is not called if gpu constructor is marked as default:

int main()
{
	struct Inner
	{
		Inner() [[cpu]]
		{
			printf("Inner\n");
		}
		Inner() [[hc]] = default;
	};
	struct Outer
	{
		Inner in;
	};
	Outer out;
	return 0;
}

This prints nothing.

When is gpu constructor removed or empty then is cpu constructor called:

int main()
{
	struct Inner
	{
		Inner() [[cpu]]
		{
			printf("Inner\n");
		}
		Inner() [[hc]] {}
	};
	struct Outer
	{
		Inner in;
	};
	Outer out;
	return 0;
}

This correctly prints "Inner".

Interesting is that in this third example constructor of Inner is called:

int main()
{
	struct Inner
	{
		Inner() [[cpu]]
		{
			printf("Inner\n");
		}
		Inner() [[hc]] = default;
	};
	Inner in;
	return 0;
}

misos1 avatar Sep 09 '18 14:09 misos1

I can reproduce this with latest rocm 1.9 release. We've opened an internal ticket for this.

david-salinas avatar Oct 11 '18 19:10 david-salinas