[Change]: A pointer in a const does not need to be non-dangling
Open
@kirtchev-adacore is already working on this.
Since Aug 7, 2026.
- Dominant language
- reStructuredText
- Stars
- 497
- Forks
- 41
- Avg merge
- 3h 52m
- Merged PRs (30d)
- 4
Description
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.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.