Thread overview
[Issue 16772] ICE when using extern(C++) and ubyte[] return value
Nov 25, 2016
ag0aep6g@gmail.com
Nov 28, 2016
Sprink
Nov 28, 2016
Atila Neves
Nov 28, 2016
Sprink
[Issue 16772] [REG2.066] ICE when using extern(C++) and ubyte[] return value
Jul 02, 2017
Vladimir Panteleev
Jul 02, 2017
Vladimir Panteleev
Jul 02, 2017
Vladimir Panteleev
Jul 16, 2019
Basile-z
Mar 21, 2020
Basile-z
November 25, 2016
https://issues.dlang.org/show_bug.cgi?id=16772

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice
                 CC|                            |ag0aep6g@gmail.com

--
November 28, 2016
https://issues.dlang.org/show_bug.cgi?id=16772

Sprink <sprink.noreply@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sprink.noreply@gmail.com

--- Comment #1 from Sprink <sprink.noreply@gmail.com> ---
(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; }

--
November 28, 2016
https://issues.dlang.org/show_bug.cgi?id=16772

--- Comment #2 from Atila Neves <atila.neves@gmail.com> ---
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.

--
November 28, 2016
https://issues.dlang.org/show_bug.cgi?id=16772

--- Comment #3 from Sprink <sprink.noreply@gmail.com> ---
(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.

--
July 02, 2017
https://issues.dlang.org/show_bug.cgi?id=16772

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang-bugzilla@thecybershad
                   |                            |ow.net
           Hardware|x86_64                      |All
            Summary|ICE when using extern(C++)  |[REG2.066] ICE when using
                   |and ubyte[] return value    |extern(C++) and ubyte[]
                   |                            |return value
           Severity|critical                    |regression

--- Comment #4 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
This appears to be a regression.

Introduced in https://github.com/dlang/dmd/pull/3160

--
July 02, 2017
https://issues.dlang.org/show_bug.cgi?id=16772

--- Comment #5 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
Err, or maybe not.

Before, it was an accepts-invalid. I guess an ice is an improvement.

--
July 02, 2017
https://issues.dlang.org/show_bug.cgi?id=16772

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[REG2.066] ICE when using   |ICE when using extern(C++)
                   |extern(C++) and ubyte[]     |and ubyte[] return value
                   |return value                |
           Severity|regression                  |critical

--
July 16, 2019
https://issues.dlang.org/show_bug.cgi?id=16772

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |b2.temp@gmx.com
         Resolution|---                         |DUPLICATE

--- Comment #6 from Basile-z <b2.temp@gmx.com> ---


*** This issue has been marked as a duplicate of issue 16575 ***

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=16772

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--