I compiled the following code with gcc and clang with -O1 and -std=c++20 flags, and it seems to work as expected.
#include <iostream>
struct S { int i; };
template<typename T>
T *get_address(T&& t) { return &t; }
void print_value_from_temporary(S *const s) {
std::cout << s->i << '\n';
s->i = 0;
std::cout << s->i << '\n';
}
int main() {
print_value_from_temporary(get_address(S{42}));
}
My question is: Is the s->i = 0; line an undefined behavior?