Possible bug when instantiating template function with nested struct
Basile B.
b2.temp at gmx.com
Sun Nov 7 16:47:51 UTC 2021
On Sunday, 7 November 2021 at 14:38:14 UTC, Alexandru Ermicioi
wrote:
> On Sunday, 7 November 2021 at 14:08:32 UTC, Basile B. wrote:
>>
>> - `.length` and `.ptr` becomes functions calls.
>> - things like `.length++` is not really supported, you have to
>> make a `Length` struct for that
>
> That would make sense, since even right now .length is not just
> a simple number, otherwise, you wouldn't be able change the
> size of an array (i.e. allocate more memory).
Actually I had in mind the simple fact to read array properties.
Good news, it turns out that this point **is not valid**, in both
cases optimizers (must be the common subexpression optim) only
read the property once (according to
[this](https://godbolt.org/z/E3eTEdWxP)).
>> - implicit conversions, templates constraints, would lead to
>> plenty of templates instances (things like `if (is(T == U[]))`
>> would require to instantiate `U[]` right ?)
>
> No idea about it being instantiated in is template. Are
> templates instantiated when doing is expression checks?
> Question to people knowledgeable about this.
>
>> - dynamic arrays are part of the type system, being `TypeNext`
>> derived they share common methods with pointers and static
>> arrays.
>
> That would be a breaking change, if the struct is not treated
> specially by compiler (i.e. compiler replacing the type).
>
>> - the internal type is still required (or plenty of special
>> cases) so that for example errors message display the type
>> representation correctly and not as lowered.
>
> So perhaps the internal type could then be a wrapper over
> struct one? Could that solve the issue with internal
> representation, and perhaps the type system (previous
> statement)?
>
>> - CTFE must use the new struct template too?
>
> What do you mean by that?
I mean it must use the AST of the new templatized struct.
>> - apparently (recently read that elsewhere) control of the
>> bound checks cannot be based on `version`
>
> Why can't they?
Because versions are not part of the mangle, so when you link you
don't know if what's been generated in a *.o has bound checks
activated or not.
More information about the Digitalmars-d
mailing list