Bug 21206 – ICE when argument or return value is string type in extern(C++) functions
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2020-08-28T16:06:22Z
Last change time
2022-05-13T15:42:45Z
Assigned to
No Owner
Creator
naydef
Comments
Comment #0 by naydef — 2020-08-28T16:06:22Z
Code:
----------------------------------
extern(C++) void Foo(string arg) {}
void main() {}
----------------------------------
Error: Internal Compiler Error: type string cannot be mapped to C++
----------------------------------
Both in run.dlang.io and Windows DMD32 v2.93.1 the error is show
The following code:
----------------------------------
import std.stdio;
extern(C++) struct Obj
{
string toString()
{
return "ret";
}
}
void main()
{
Obj obj1;
writefln("%s", obj1);
}
----------------------------------
Generates error only on Windows DMD32 v2.93.1, but not in run.dlang.io.
Adding extern(D) to the toString() fixes the error.
Comment #1 by greeenify — 2020-08-28T23:10:33Z
The reason for the different behaviour with string argument is that there's cppmangle.d for Posix and cppmanglewin.d for Windows.
There's an old PR for both issues: https://github.com/dlang/dmd/pull/8120
Comment #2 by ibuclaw — 2022-05-13T15:42:45Z
*** This issue has been marked as a duplicate of issue 16575 ***