https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96414
Bug ID: 96414
Summary: Second char relation test incorrect with constexpr
dynamic allocation
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pkeir at outlook dot com
Target Milestone: ---
Created attachment 48981
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48981&action=edit
The file containing the code described.
The attached C++20 code behaves differently at compile-time than at runtime,
but shouldn't. As with `__gnu_cxx::char_traits<char>::lt`, the function
`lt_fun` applies built-in `operator<` to two character references, and returns
the result as an `int`. However, with the character pointer `pc` pointing to
memory allocated dynamically, the second call returns true (1) indicating that
'a' < 'a' is true. This is demonstrated by a failing static assert. Commenting
out the static assert produces an executable which correctly reports that 'a' <
'a' is false; by returning a 0.