Bug 16772 – ICE when using extern(C++) and ubyte[] return value

Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2016-11-25T09:51:14Z
Last change time
2020-03-21T03:56:37Z
Keywords
ice
Assigned to
No Owner
Creator
Atila Neves

Comments

Comment #0 by atila.neves — 2016-11-25T09:51:14Z
extern(C++) ubyte[] foo() { return []; } dmd foo.d: Error: Internal Compiler Error: unsupported type ubyte[]
Comment #1 by sprink.noreply — 2016-11-28T18:14:24Z
(In reply to Atila Neves from comment #0) > extern(C++) ubyte[] foo() { return []; } > > dmd foo.d: > > Error: Internal Compiler Error: unsupported type ubyte[] There is no equivalent C++ type that can be represented by "ubyte[]". In D an array consists of a pointer and a size. In C++ an array is essentially just a pointer. This code will result in a compiler error in C++, as the two functions have the same signature. void foo(int* in) { } void foo(int in[]) { } Use a pointer if you want the function to be extern(C++) extern(C++) ubyte* foo() { return null; }
Comment #2 by atila.neves — 2016-11-28T18:22:38Z
I should have myself a bit clearer: I don't expect to be able to call a function that returns `ubyte[]` from C++. I expect the compiler to not crash and tell me what it is I did that was wrong. What happened to me is I had `extern(C++):` in a file that ended with only functions supposed to be called from C++. Then I added another function at the end and got the ICE. Notice as well that there is no file or line information in the error message. I'd made several changes at once and had to figure out exactly where this error was coming from (how is ubyte[] not supported??). Also, `extern(C)` doesn't crash the compiler. Or generate an error, and I'm not sure which is worse.
Comment #3 by sprink.noreply — 2016-11-28T18:28:58Z
(In reply to Atila Neves from comment #2) > I should have myself a bit clearer: I don't expect to be able to call a > function that returns `ubyte[]` from C++. I expect the compiler to not crash > and tell me what it is I did that was wrong. What happened to me is I had > `extern(C++):` in a file that ended with only functions supposed to be > called from C++. Then I added another function at the end and got the ICE. > > Notice as well that there is no file or line information in the error > message. I'd made several changes at once and had to figure out exactly > where this error was coming from (how is ubyte[] not supported??). > > Also, `extern(C)` doesn't crash the compiler. Or generate an error, and I'm > not sure which is worse. I see what you mean now, yah it should definitely be more informative. For the extern(C) part, it shouldn't be an error, extern(C) is just a convention. It has no type information in the mangled name, so ubyte[] won't have to be mangled to match something that C doesn't have. If you have a function with extern(C) used, then D calls a function like GetProcAddress, it can then cast it to proper function type with ubyte[] and use it fine. So I don't really see why it should be an error.
Comment #4 by dlang-bugzilla — 2017-07-02T00:03:57Z
This appears to be a regression. Introduced in https://github.com/dlang/dmd/pull/3160
Comment #5 by dlang-bugzilla — 2017-07-02T00:05:17Z
Err, or maybe not. Before, it was an accepts-invalid. I guess an ice is an improvement.
Comment #6 by b2.temp — 2019-07-16T20:59:03Z
*** This issue has been marked as a duplicate of issue 16575 ***