Skip to content

Compile error during assignment to double-pointer with bounds-safe interface #797

Closed
@nmeum

Description

@nmeum

Consider the following code:

#include <stdio.h>

void
myfunc(int **outval : itype(_Ptr<_Ptr<int>>)) {
	static int val = 5;

	_Ptr<int> myptr = &val;

	// Doesn't work:
	*outval = myptr;
	// This does work:
	/* *outval = &val; */
}

int
main(void)
{
	int *myval;

	myfunc(&myval);
	printf("myval = %d\n", *myval);
}

This does not compile with the following error message:

$ clang -o test test.c
test.c:10:10: error: assigning to 'int *' from incompatible type '_Ptr<int>'
        *outval = myptr;
                ^ ~~~~~
1 error generated

If the code is changed according to the comment in myfunc it does compile. Alternatively, it does also compile successfully if myfunc() uses Checked C pointer types directly instead of using a bound-safe interface. I find this a bit surprising, is this is a bug or intended behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions