https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89149
Bug ID: 89149
Summary: Out of bounds array access not detected as ill-formed
in a constant expression context in some cases
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: yaghmour.shafik at gmail dot com
Target Milestone: ---
Given the following C++ example:
void foo() {
constexpr char c1 =
(&(&"abc"[2])[-1])[-3];
constexpr char c2 =
(&(&(&"abc"[2])[-1])[-3])[4];
}
Both declarations should be ill-formed since we have out of bounds array access
in a constant expression context. gcc correctly produces a diagnostic for c1
but not for c2. See live godbolt:
https://godbolt.org/z/z7MrES
Both clang and icc produce a diagnostic for both cases and as indicated here so
does EDG https://twitter.com/zygoloid/status/1090863346016907264