Skip to content

[Change]: A pointer in a const does not need to be non-dangling #716

Description

@inkreasing

Change description

Currently the fls states that a pointer in a const shall be non-dangling. The compiler accepts a raw dangling pointers in constants.

Area

const evaluation

Category

Bug

FLS Paragraph ID

ls_l1FOH8zt0XRZ

Change description (extended)

fn main() {
    // accepted by the compiler
    const A: *const u8 = std::ptr::dangling();
    const B: *const u8 = std::ptr::null();
    // not accepted by the compiler    
    //const C: &u8 = unsafe { &(*std::ptr::dangling()) };
}

This creates a dangling pointer.
Maybe the text should be changed to say reference instead of pointer?

(i am sorry if i misunderstood the use of "shall". I looked at 1.3.5 and it seems to me that shall is used for rules that the programmer has to follow either to make the compiler accept the program or to avoid UB. But this is both accepted by the compiler and not UB.)

Metadata

Metadata

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