Thread overview
[Issue 15505] extern(C++) array parameter mangling gains surprise const
Jan 06, 2016
Manu
Jul 02, 2017
Vladimir Panteleev
Oct 26, 2017
Walter Bright
Mar 23, 2018
Manu
Jun 11, 2019
Dlang Bot
Jun 11, 2019
Nicholas Wilson
Jun 11, 2019
kinke@gmx.net
Jun 28, 2019
Manu
Dec 17, 2022
Iain Buclaw
January 06, 2016
https://issues.dlang.org/show_bug.cgi?id=15505

Manu <turkeyman@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|cxtern(C++) array parameter |extern(C++) array parameter
                   |mangling gains surprise     |mangling gains surprise
                   |const                       |const

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |C++
           Hardware|x86_64                      |All
           Severity|enhancement                 |normal

--- Comment #1 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
Only occurs when targeting the MS toolchain (-m64 / -m32mscoff).

-m32mscoff:
mangled: ?f@@YAXQAY03H@Z
demangled: void __cdecl f(int (* const)[4])

-m64:
mangled: ?f@@YAXQEAY03H@Z
demangled: void __cdecl f(int (* __ptr64 const)[4])

--
October 26, 2017
https://issues.dlang.org/show_bug.cgi?id=15505

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |mangling
                 CC|                            |bugzilla@digitalmars.com

--
March 23, 2018
https://issues.dlang.org/show_bug.cgi?id=15505

Manu <turkeyman@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
June 11, 2019
https://issues.dlang.org/show_bug.cgi?id=15505

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@thewilsonator created dlang/dmd pull request #10020 "Fix issue 15505 - extern(C++) array parameter mangling gains surprise const" fixing this issue:

- Fix issue 15505 - extern(C++) array parameter mangling gains surprise const

https://github.com/dlang/dmd/pull/10020

--
June 11, 2019
https://issues.dlang.org/show_bug.cgi?id=15505

Nicholas Wilson <iamthewilsonator@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iamthewilsonator@hotmail.co
                   |                            |m

--- Comment #3 from Nicholas Wilson <iamthewilsonator@hotmail.com> ---
This is the * const problem all over again.

--
June 11, 2019
https://issues.dlang.org/show_bug.cgi?id=15505

kinke@gmx.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #4 from kinke@gmx.net ---
(In reply to Manu from comment #0)
> Nobody uses *const in C++.

Don't forget Microsoft; you've already reported a similar MS-specific issue a while back, with the C++ new operator or some other allocator IIRC.

Well, here we go again:

C++: short test27(int arg[6]); // or `int arg[]`, same thing

Win64: ?test27@@YAFQEAH@Z [short test27(int * const)]
Linux: _Z6test27Pi [test27(int *)]

I don't think this C++ function can be declared directly and portably in D anyway.

But due to this const-hack, it apparently works in higher dimensions: one can represent C++ `int p[][6]` as `int[6]* p` in D, and that does indeed work portably for both MSVC and Itanium.

https://github.com/dlang/dmd/blob/7538ed0125531d3a49ea6d2e266f7bae6e83556f/src/dmd/cppmanglewin.d#L282-L283:

> attention: D int[1][2]* arr mapped to C++ int arr[][2][1]; (because it's more typical situation)
> There is not way to map int C++ (*arr)[2][1] to D

Still, I think that special case is not worth it and more confusing than useful. It's been there since 2014 or longer: https://github.com/dlang/dmd/pull/3160

--
June 28, 2019
https://issues.dlang.org/show_bug.cgi?id=15505

--- Comment #5 from Manu <turkeyman@gmail.com> ---
I don't follow your examples:
C++:
  void test(int arg[6]);
  void test(int arg[]);

These are identical in C++, and they should mangle the same; with no size. And yes, we see that MSVC has `* const` here. This is actually uninteresting, because there's no way to make a declaration like this in D. In C++, it's just a lame way to pass an un-sized array, and would almost always just use a pointer.


This is what's interesting:

C++:
  void test(int (&arg)[6]);
  void test(int (*arg)[6]);

These are interesting because they have meaningful D counterparts:
  void test(ref int[6]);
  void test(int[6]*);

These cases should be fixed in our mangler, they are useful functions that appear relatively often and are the proper way to pass static-arrays in C++.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=15505

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--