void main() { scope string s; s = "`" ~ s ~ "`"; } Compile with the -betterC flag onlineapp.d:4: error: undefined reference to '_D12TypeInfo_Aya6__initZ' onlineapp.d:4: error: undefined reference to '_d_arraycatnTX' onlineapp.o:onlineapp.d:function main: error: undefined reference to '_d_run_main' collect2: error: ld returned 1 exit status Error: linker exited with status 1
What is the expected result? I'm not too familiar with how -betterC works, so I'm not sure whether it should complain that it can't use concatenation, or you expect it to work. How do other attempts to use the runtime fare?
> What is the expected result? If TypeInfo is indeed required to perform string concatenation, then the compiler should emit a compile-time error by checking the `global.params.usetypeinfo` flag. This can be implemented very easily today, but I think that this is a symptom of a more systematic problem in D. I'm skeptical that TypeInfo is a necessity for this operation, and ideally TypeInfo should not be required. Removing the dependency on TypeInfo would remove the reference to '_D12TypeInfo_Aya6__initZ'. The runtime hook `_d_arraycatnTx` could probably be replaced with a template, which would result in a compile-time error saying that it can't find/instantiate the template.
This is one of those "magic" calls from the compiler to the runtime. I agree it can be replaced with a template, and then the linker error will be replaced with a compile time error (or maybe one can provide a betterC runtime that works without druntime?) The TypeInfo is how the old-time runtime functions communicated the type. There is slow but steady progress to replace these calls with template calls, allowing the runtime more control over what happens.
Array concatenation still implies automatic memory management of some form. Not sure something like that can fit in betterC. You can implement something like stringConcat("`",s,"`") that will use memory management of your choice. Or char[] buffer=...; "`".chain(s).chain("`").copy(buffer);
The example needs to declare main() as extern(C). Anyhow, the trouble is _d_arraycatnTX(), which is in druntime and uses the GC to allocate the destination array.
https://github.com/dlang/dmd/pull/7868
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2a671e0bbfa37427f73494ecca79144e659e0122 fix Issue 18312 - string concatenation with -betterC fails with linker errors https://github.com/dlang/dmd/commit/2bb137a0f7a856a9331d44b3b4df5aa47b865816 Merge pull request #7868 from WalterBright/fix18312 fix Issue 18312 - string concatenation with -betterC fails with linke…