public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108537] New: constexpr UB pointer dereference compiles if the dereferenced value is not used
@ 2023-01-25 10:35 ed at edwardrosten dot com
0 siblings, 0 replies; only message in thread
From: ed at edwardrosten dot com @ 2023-01-25 10:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108537
Bug ID: 108537
Summary: constexpr UB pointer dereference compiles if the
dereferenced value is not used
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ed at edwardrosten dot com
Target Milestone: ---
The following code compiles successfully:
constexpr int a(){
int* b = new int[1];
int r= &b[100]-b; //UB
b[100]; //UB
delete[] b;
return r;
}
template<int X> int N=0;
int foo(){
return N<a()>;
}
b[100] is unconditionally undefined behaviour, even though the value is never
used.
Tested on a scattering of versions (10.3, 11.2, 12.2) with -std=c++2a -O2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-25 10:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25 10:35 [Bug c++/108537] New: constexpr UB pointer dereference compiles if the dereferenced value is not used ed at edwardrosten dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).