diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-02-21 08:18:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-21 08:18:31 -0800 |
| commit | 433ce869481b72ad44897dcc91d7038b03ba45e2 (patch) | |
| tree | d8fbe73bea7ca800485dd57b508e50c01d882a35 /source/slang/slang-parser.cpp | |
| parent | 1f401d04e32c6feaeb35243ea5bfc2b14520344b (diff) | |
Initial support for explicit default initializers (#1235)
This change makes it so that for a suitable type `MyType`, a variable declaration like:
MyType v;
is treated as if it were written:
MyType v = MyType();
The definition of "suitable" here is that `MyType` needs to have an available `__init` declaration that can be invoked with zero arguments. I've added a test to confirm that the new behavior works in this specific case.
There are a bunch of caveats to the feature as it stands today:
* Just because `MyType` has a zero-parameter `__init`, that doesn't mean an array type like `MyType[10]` does, so arrays currently remain uninitialized by default. Fixing this gap requires careful consideration because some, but not all, array types should be default-initializable.
* The change here should mean that a `struct` type with a field like `MyType f;` should count as having a default initial-value expression for that field, but I haven't confirmed that.
* Even if a `struct` provides initial values for all its fields (e.g., `struct S { float f = 0; }`), that doesn't mean it has a default `__init` right now, so those `struct` types will still be left uninitialized by default. Converging all this behavior is still TBD.
Just to be clear: there is no provision or plan in Slang to support destructors, RAII, copy constructors, move constructors, overloaded assignment operations, or any other features that buy heavily into the C++ model of how construction and destruction of values gets done.
In fact, I'm not even 100% sure I like having this change in place at all, and I think we should reserve the right to revert it and say that only specific stdlib types get to opt in to default initialization along these lines.
Diffstat (limited to 'source/slang/slang-parser.cpp')
0 files changed, 0 insertions, 0 deletions
