summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-08-06 12:14:52 -0700
committerGitHub <noreply@github.com>2019-08-06 12:14:52 -0700
commit81ce78d08a7e3fbe74f2fd41c5a258ea4b078245 (patch)
tree06e0c3cae361ee85cbee513ee539d9f9bde647f9 /source/slang/slang.cpp
parent89758544c45a15e546a1eb08891e2787bb88de4a (diff)
Add support for the HLSL "cast from zero" idiom (#1008)
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.
Diffstat (limited to 'source/slang/slang.cpp')
0 files changed, 0 insertions, 0 deletions