D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4893 - Function pointer assignments ignore constness
Summary: Function pointer assignments ignore constness
Status: RESOLVED DUPLICATE of issue 3797
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 2573
  Show dependency treegraph
 
Reported: 2010-09-18 17:13 UTC by Jonathan M Davis
Modified: 2010-10-19 11:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2010-09-18 17:13:04 UTC
Take this program:

struct S
{
public:

    this(int[] function(const int[])func)
    {
        _func = func;
    }

    @property int[] function(const int[]) func()
    {
        return func;
    }

private:
    int[] function(const int[]) _func;
}

int[] add1(int[] num)
{
    return num ~ 1;
}

void main()
{
    auto s = S(&add1);
}

It shouldn't compile, but it does. add1() does not take a const int[] and therefore could theoretically modify its arguments (though it doesn't here), violating the type of the function pointer. Using in and immutable instead of const has the same problem. They compile when they shouldn't.
Comment 1 Jonathan M Davis 2010-09-18 17:14:59 UTC
Oh, there's an error in my example - func return func instead of _func, resulting infinite recursion and therefore a segfault. I could have removed that function for the bug report anyway.
Comment 2 anonymous4 2010-10-19 11:03:16 UTC

*** This issue has been marked as a duplicate of issue 3797 ***