https://github.com/shader-slang/slang
Revision 81ce78d08a7e3fbe74f2fd41c5a258ea4b078245 authored by Tim Foley on 06 August 2019, 19:14:52 UTC, committed by GitHub on 06 August 2019, 19:14:52 UTC
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.
1 parent 8975854
History
Tip revision: 81ce78d08a7e3fbe74f2fd41c5a258ea4b078245 authored by Tim Foley on 06 August 2019, 19:14:52 UTC
Add support for the HLSL "cast from zero" idiom (#1008)
Tip revision: 81ce78d
File Mode Size
docs
examples
external
source
tests
tools
.editorconfig -rw-r--r-- 937 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 480 bytes
.gitmodules -rw-r--r-- 406 bytes
.travis.yml -rw-r--r-- 1.7 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 6.7 KB
appveyor.yml -rw-r--r-- 3.7 KB
premake5.lua -rw-r--r-- 26.7 KB
slang-com-helper.h -rw-r--r-- 4.8 KB
slang-com-ptr.h -rw-r--r-- 4.8 KB
slang.h -rw-r--r-- 107.4 KB
slang.sln -rw-r--r-- 9.8 KB
test.bat -rw-r--r-- 1.4 KB
travis_build.sh -rw-r--r-- 304 bytes
travis_test.sh -rw-r--r-- 435 bytes

README.md

back to top