https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124347
Bug ID: 124347
Summary: __builtin_object_size/__builtin_dynamic_object_size
doesn't work in constexpr contexts
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
constexpr int
foo (const char *p)
{
return __builtin_dynamic_object_size (p, 0);
}
constexpr int
bar (int x)
{
char *a = new char[x];
int b = foo (a);
delete [] a;
return b;
}
constexpr int
baz (const char *p)
{
return __builtin_object_size (p, 1);
}
constexpr int
qux (int x)
{
char *a = new char[x];
int b = baz (a);
delete [] a;
return b;
}
static_assert (bar (42) == 42);
static_assert (qux (142) == 142);
constexpr char a[] = "foobar";
static_assert (foo (a) == 7);
static_assert (baz (a) == 7);
static_assert (foo ("foo") == 4);
static_assert (baz ("baz") == 4);