Jump to page: 1 2
Thread overview
[Issue 21537] Function pointer* pointer' attributes not covariant when referencing (delegates' are)
[Issue 21537] Function pointers' attributes not covariant when referencing (delegates' are)
Jan 09, 2021
Bolpat
Jan 09, 2021
Bolpat
Nov 22, 2021
Bolpat
Nov 22, 2021
Bolpat
Nov 27, 2021
Bolpat
Nov 27, 2021
Bolpat
[Issue 21537] Pointer to function pointer cannot be converted to pointer to const function pointer with lower attributes
Nov 27, 2021
Bolpat
Dec 07, 2021
Bolpat
Dec 17, 2022
Iain Buclaw
January 09, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |qs.il.paperinik@gmail.com

--
January 09, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

--- Comment #1 from Bolpat <qs.il.paperinik@gmail.com> ---
Related:

interface I
{
    void f(const(void function() @safe)* fpp) @safe;
    void g(const(void delegate() @safe)* dgp) @safe;
}

class C : I
{
    override void f(const(void function())* fpp) @safe { } // error
(unexpected)
    override void g(const(void delegate())* fpp) @safe { } // okay (expected)
}

--
November 05, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg
            Summary|Function pointers'          |Function pointer* pointer'
                   |attributes not covariant    |attributes not covariant
                   |when referencing            |when referencing
                   |(delegates' are)            |(delegates' are)

--
November 05, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from moonlightsentinel@disroot.org ---
The premise of this bug report is wrong, it passes a_pointer_ to a function pointer instead of the function pointer. This fails because pointer conversions are only allowed if the pointee is const-convertible to the target.

This is could be replaced by an enhancement request to make an exception for attribute changes in function pointers. But that would be an odd special case.

The interface example is a duplicate of 21538

--
November 22, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

--- Comment #3 from Bolpat <qs.il.paperinik@gmail.com> ---
> The premise of this bug report is wrong, it passes a_pointer_ to a function pointer instead of the function pointer.

How is a pointer to a function pointer morally different from a pointer to a delegate or a pointer to a class object reference?

If types T and S have a subtyping relationship like T ⊆ S, then const(T)* ⊆ const(S)*; at least, this is the case when T and S are class types or when T and S are delegate types, but fails when T and S are function pointer types.

--
November 22, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---
           Severity|normal                      |enhancement

--
November 22, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

--- Comment #4 from moonlightsentinel@disroot.org ---
(In reply to Bolpat from comment #3)
> How is a pointer to a function pointer morally different from a pointer to a delegate or a pointer to a class object reference?

It isn't.

> If types T and S have a subtyping relationship like T ⊆ S, then const(T)* ⊆ const(S)*; at least, this is the case when T and S are class types or when T and S are delegate types, but fails when T and S are function pointer types.

No, such implicit conversion for pointer are already rejected:

class A {}
class B : A {}

alias SysFP = void function();
alias SafeFP = void function() @safe;

alias SysDG = void delegate();
alias SafeDG = void delegate() @safe;

void main()
{
    {
        A a;
        B b;
        a = b; // Fine
    }{
        A* ap;
        B* bp;
        ap = bp; // Error: cannot implicitly convert expression `bp` of type
`B*` to `A*`
    }{
        SafeFP safeFp;
        SysFP sysFp;
        sysFp = safeFp; // Fine
    }{
        SafeFP* safeFpPtr;
        SysFP* sysFpPtr;
        sysFpPtr = safeFpPtr; // Error: cannot implicitly convert expression
`safeFpPtr` of type `void function() @safe*` to `void function()*`
    }{
        SafeDG safeDg;
        SysDG sysDg;
        sysDg = safeDg; // Fine
    }{
        SafeDG* safeDgPtr;
        SysDG* sysDgPtr;
        sysDgPtr = safeDgPtr; // Error: cannot implicitly convert expression
`safeDgPtr` of type `void delegate() @safe*` to `void delegate()*`
    }
}

--
November 27, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

--- Comment #5 from Bolpat <qs.il.paperinik@gmail.com> ---
(In reply to moonlightsentinel from comment #4)
> (In reply to Bolpat from comment #3)
> > How is a pointer to a function pointer morally different from a pointer to a delegate or a pointer to a class object reference?
> 
> It isn't.
> 
> > If types T and S have a subtyping relationship like T ⊆ S, then const(T)* ⊆ const(S)*; at least, this is the case when T and S are class types or when T and S are delegate types, but fails when T and S are function pointer types.
> 
> No, such implicit conversion for pointer are already rejected:
> 
> [code]

Of course, if you don't use const, the conversion is not safe. But I did. I
checked it again if I missed it at some point by accident, but at a quick
glance I couldn't find a spot. (Even if there is one, the overall use of const
makes clear what I'm talking about.) Your example demonstrates conversation to
a pointer a mutable supertype object, but the bug report is about pointers to a
const supertype object.
Neither of us is wrong, but we're talking about slightly, but meaningfully
different things. The code you posted is rejected and for good reasons, but it
does not invalidate the bug report.

--
November 27, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal

--
November 27, 2021
https://issues.dlang.org/show_bug.cgi?id=21537

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Function pointer* pointer'  |Pointer to function pointer
                   |attributes not covariant    |cannot be converted to
                   |when referencing            |pointer to const function
                   |(delegates' are)            |pointer with lower
                   |                            |attributes

--
« First   ‹ Prev
1 2