Bug 15505 – extern(C++) array parameter mangling gains surprise const

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2016-01-03T12:13:03Z
Last change time
2024-12-13T18:46:15Z
Keywords
C++, industry, mangling, pull
Assigned to
No Owner
Creator
Manu
Moved to GitHub: dmd#19082 →

Comments

Comment #0 by turkeyman — 2016-01-03T12:13:03Z
extern(C++) void f(int[4]* t); Mangles as: void __cdecl f(int (* const)[4]) Where did that const come from? This would logically be connected to a C++ function declared: void f(int(*x)[4]); Which mangles: void __cdecl f(int (*)[4]) I think it very unlikely that any C++ user would have functions: void f(int(*const x)[4]); Nobody uses *const in C++.
Comment #1 by dlang-bugzilla — 2017-07-02T16:53:44Z
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])
Comment #2 by dlang-bot — 2019-06-11T08:46:23Z
@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
Comment #3 by iamthewilsonator — 2019-06-11T14:16:19Z
This is the * const problem all over again.
Comment #4 by kinke — 2019-06-11T20:58:37Z
(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
Comment #5 by turkeyman — 2019-06-28T00:31:14Z
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++.
Comment #6 by robert.schadek — 2024-12-13T18:46:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19082 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB