D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18312 - string concatenation with -betterC fails with linker errors
Summary: string concatenation with -betterC fails with linker errors
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: betterC
Depends on:
Blocks:
 
Reported: 2018-01-27 08:02 UTC by Mike Franklin
Modified: 2018-02-12 04:12 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mike Franklin 2018-01-27 08:02:13 UTC
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
Comment 1 Steven Schveighoffer 2018-01-28 18:55:36 UTC
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?
Comment 2 Mike Franklin 2018-01-28 23:48:14 UTC
> 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.
Comment 3 Steven Schveighoffer 2018-01-28 23:53:39 UTC
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.
Comment 4 anonymous4 2018-01-31 08:59:13 UTC
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);
Comment 5 Walter Bright 2018-02-10 10:19:13 UTC
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.
Comment 7 github-bugzilla 2018-02-12 04:12:38 UTC
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…