Skip to content

Address-of (&) a pointer with unknown bounds should be valid #881

Open
@dopelsunce

Description

@dopelsunce

The spec allows us to take the address of a checked pointer with unknown bounds.
However, explicitly annotating a pointer with bounds(unknown) and then taking its address trigger a compiler error:

int main() {
    _Array_ptr<int> p : bounds(unknown);
    (void)&p;
    return 0;
}
test1.c:3:12: error: cannot take address of variable 'p' with bounds
    (void)&p;
           ^
test1.c:2:25: note: bounds declared here
    _Array_ptr<int> p : bounds(unknown);
                        ^~~~~~~~~~~~~~~
1 error generated.

There is no error if p is declared without bounds annotation:

int main() {
    _Array_ptr<int> p;
    (void)&p;
    return 0;
}

But p has unknown bounds by default in the above snippet. It's surprising that adding a redundant bounds(unknown) annotation causes the compiler to reject the code.

Metadata

Metadata

Assignees

Labels

bugThis labels issues that are bugs.priority:2This labels bugs that require immediate attention.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions