[Issue 18238] Templates only used during CTFE shouldn't be code-gened

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 19 23:00:41 UTC 2018


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

Jonathan Marler <johnnymarler at gmail.com> changed:

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

--- Comment #1 from Jonathan Marler <johnnymarler at 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.

--


More information about the Digitalmars-d-bugs mailing list