<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/tests/compute/cast-zero-to-struct.slang.expected.txt, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2019-08-06T19:14:52+00:00</updated>
<entry>
<title>Add support for the HLSL "cast from zero" idiom (#1008)</title>
<updated>2019-08-06T19:14:52+00:00</updated>
<author>
<name>Tim Foley</name>
<email>tfoleyNV@users.noreply.github.com</email>
</author>
<published>2019-08-06T19:14:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=81ce78d08a7e3fbe74f2fd41c5a258ea4b078245'/>
<id>urn:sha1:81ce78d08a7e3fbe74f2fd41c5a258ea4b078245</id>
<content type='text'>
If the user writes code like this:

    MyStruct s = (MyStruct) 0;

then we will interpret it as if they had written:

    MyStruct s = {};

That is, the "cast from zero" idiom will be taken as a legacy syntax for default construction (using an empty initializer list). This will be semantically equivalent to zero-initialization for all existing HLSL code (where `struct` fields can't have default initialization expressions defined), and is the easiest option for us to support in Slang (since we already support default-initialization using empty initializer lists).

The implementation of this feature is narrowly scoped:

* It only targets explicit cast expressions like `(MyStruct) 0` and not "constructor" syntax like `MyStruct(0)`
* It only applies when there is a single argument that is exactly an integer literal with a zero value (not a reference to a `static const int` that happens to be zero).

This change adds a test case to make sure that the feature works as expected. Because it relies on our existing initializer-list handling, the "cast from zero" idiom should work for any user-defined type where an initializer list would work.</content>
</entry>
</feed>
