`ref T` should be a type!!

Manu turkeyman at gmail.com
Thu Apr 4 17:20:01 UTC 2019


On Thu, Apr 4, 2019 at 4:15 AM Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 4/4/19 4:33 AM, Manu wrote:
> > On Tue, Apr 2, 2019 at 4:10 AM Andrei Alexandrescu via Digitalmars-d
> > <digitalmars-d at puremagic.com> wrote:
> >>
> >> On 4/2/19 4:11 AM, Walter Bright wrote:
> >>> On 4/1/2019 5:55 PM, Atila Neves wrote:
> >>>> Factually incorrect.
> >>>
> >>> I suspect Rubn has confused the syntactical conflation of arrays with
> >>> pointers in C, and the implicit coercion of arrays to pointers, as them
> >>> being the same. They simply aren't the same, as they are semantically
> >>> separated by one level of indirection.
> >>
> >> You forgot to mention that top-level "const" is ignored in function
> >> parameters (for the signature and mangling but not the implementation).
> >
> > Actually, it's sadly not ignored, and MSVC mangles it!
>
> I'd be surprised. It would be a gross bug. It didn't in 2004 when I
> still was using it. Herb advocates using top-level const in
> implementation, pointing out that it's ignored in the signature.

Herb appears to be wrong.
And this is his native STL, he should know ;)

> > It's been a
> > massive PITA when writing some of the STL bindings in druntime!
> > I've had to manually build mangled function names to extern, because I
> > can't express it in D >_<
> >
> > https://github.com/dlang/druntime/blob/master/src/core/stdcpp/allocator.d#L50
> >   <- you're loving it!
>
> Could that be a "pointer to const"? That's not top-level.

Straight from the STL: xmemory0:989

template<class _Ty>
class allocator
{ // generic allocator for objects of class _Ty
public:
  ...
  void deallocate(_Ty * const _Ptr, const size_t _Count)
  { // deallocate object at _Ptr
    // no overflow check on the following multiply; we assume
_Allocate did that check
    _Deallocate<_New_alignof<_Ty>>(_Ptr, sizeof(_Ty) * _Count);
  }
}

I spent hours trying to work out why the mangling was failing before I
noticed the const was in the wrong place in the C++ code. Only
solution is the code I linked above.
Also, FWIW, I think this is a fairly recent change (ie, last 5 years).


More information about the Digitalmars-d mailing list