Thread overview
[Issue 18238] Templates only used during CTFE shouldn't be code-gened
Jan 19, 2018
Jonathan Marler
Dec 17, 2022
Iain Buclaw
January 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18238

Jonathan Marler <johnnymarler@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johnnymarler@gmail.com

--- Comment #1 from Jonathan Marler <johnnymarler@gmail.com> ---
I'm not sure this is a good example.  I don't think the compiler can actually determine that it doesn't need to bring the entire string into object code. For example, if you had done:

printf("%s", s.ptr);

then the expected behavior would be to print the entire string (at least from offset 2).  But the only thing that was changed was the format specifier in the printf statement, which means that the D compiler would have had to understand the format specifier to know whether or not it needed to bring the entire string to object code.  But you can imagine other examples, such as an extern(C) function that takes a null-terminated string of which the compiler cannot determine anything about.  If you passed the return value of foo to that function then you have to bring the whole string into object code.

I don't think that slicing a string literal is enough for the compiler to only bring that slice to object code.  This would result in astonishing behavior.

```
immutable someString = "hello"[0 .. 1];
void foo()
{
    printf("%s\n", someString.ptr);
}
```

I would expect this to print "hello", but if the compiler only brought "h" to object code than I would be very confused.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18238

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=18238

--- Comment #2 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19364

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--