[Issue 17435] bogus "need 'this'" error with aggregate field passed in alias parameter

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu May 25 20:56:41 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17435

Vladimir Panteleev <thecybershadow at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow at gmail.com

--- Comment #1 from Vladimir Panteleev <thecybershadow at gmail.com> ---
(In reply to ag0aep6g from comment #0)
> This should compile:

AFAIU, detecting whether an alias parameter should be passed with context or
not is a difficult problem because it changes the function's mangling and ABI
signature.

> Works when `ft` is marked as `static`, which should be a NOP:

Here static applies to the template, not function. You can observe this by
explicitly rewriting the function template into an eponymous template.

> Curiously, taking a function pointer and calling it also works

It looks like you found a different bug here. A function template that takes an
alias parameter can be implicitly cast to a function pointer, even when it uses
the alias parameter:

---
struct S { int field; }
int ft(alias a)() { return a; }
alias f = ft!(S.field);

void main()
{
    int function() fptr = &f; /* accepted */
    int i = fptr(); /* accepted and passes */
}
---

The above compiles and segfaults at runtime.

That should be filed as a separate accepts-invalid bug.

--


More information about the Digitalmars-d-bugs mailing list