Authors: Jay Ghiron
Date: 2026-06-25
Submitted against: C23
Status: Open
Cross-references: 0452
This issue comes from GCC issue 121376. Consider the following program:
int main(){
struct{int x[1];}x={};
int*p;
return p=(0,x).x,*x.x=1,*p;
}
A structure object x containing an array of one integer with the
value zero is created. A structure object with temporary lifetime
whose value is the same as x is created by the expression (0,x).
A pointer p is created which refers to the integer object inside of
the structure object with temporary lifetime. The integer object
inside of x is assigned the value one. The value of the object
pointed to by p is returned from main. Following these steps it
appears that the result should be zero, which is what Clang returns.
GCC and MSVC instead return one, because they do not give different
addresses to the structure object with temporary lifetime and x.
DR 452 considered the case of comparing the addresses,
which is inconsequential so it added the wording:
An object with temporary lifetime behaves as if it were declared with the type of its value for the purposes of effective type. Such an object may not have a unique address.
(C23 6.2.4 "Storage durations of objects" paragraph 8.)
The structure object with temporary lifetime does not have a unique
address, but x does have a unique address. So it appears that they
cannot share addresses, otherwise the uniquity of x would be
violated. Regardless, the response to DR 452 indicates
that they actually can share addresses. Though doing so in this
scenario causes a mutable object to overlap with another object, which
in combination with:
Any attempt to modify an object with temporary lifetime results in undefined behavior.
(C23 6.2.4 "Storage durations of objects" paragraph 8.)
It appears that modifying x could be considered modifying the
structure object with temporary lifetime, causing undefined behavior.
Can objects with temporary lifetime overlap with objects other than
string literals, objects created from compound literals with const
qualified type, and other objects with temporary lifetime?
If the answer to question one is that objects with temporary lifetime can overlap with those objects, does mutating an object which it overlaps with cause undefined behavior?
If the answer to question one is that objects with temporary lifetime can overlap with those objects, are there any limitations on what objects can be overlapped with? For example:
#include<stdio.h>
struct X{char x[32];};
struct X get(){
return(struct X){"a string"};
}
int main(){
puts(get().x);
}
Is there anything preventing the structure object with temporary
lifetime here from overlapping with some object that gets modified
during the execution of puts?