Difference in the end of lifetime rules? : <p><a href="https://en.cppreference.com/w/cpp/language/lifetime" rel="noreferrer">https://en.cppreference.com/w/cpp/language/lifetime</a> in <strong>Notes</strong> section has this code, reproduced here:</p>

<pre><code>struct A {
  int* p;
  ~A() { std::cout &lt;&lt; *p; } // if n outlives a, prints 123
};
void f() {
  A a;
  int n = 123; // if n does not outlive a, this is optimized out (dead store)
  a.p = &amp;n;
}
</code></pre>

<p>What is it trying to say in this <strong>Notes</strong> section? </p>

<p>From what I understand, the code is UB (or is it) as it's clear that <code>n</code> does not outlive <code>a</code>.</p>

<p>What does it mean by:</p>

<blockquote>
  <p>difference in the end of lifetime rules between non-class objects (end
  of storage duration) and class objects (reverse order of construction)
  matters</p>
</blockquote>

<p>But it does not say matter <strong>how</strong>.</p>

<p>I am very confused by this entire section.</p>
