Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, the relevant part of the spec is 6.7/4:</p> <blockquote> <p>An implementation is permitted to perform early initialization of other local objects with static storage duration under the same conditions that an implementation is permitted to statically initialize an object with static storage duration in namespace scope (3.6.2). Otherwise such an object is initialized the first time control passes through its declaration; such an object is considered initialized upon the completion of its initialization.</p> </blockquote> <p>Assuming the second part holds (<code>object is initialized the first time control passes through its declaration</code>), your code can be considered thread safe.</p> <p>Reading through 3.6.2, it appears the early initialization permitted is converting <em>dynamic-initialization</em> to <em>static-initialization</em>. Since <em>static-initialization</em> must happen before any <em>dynamic-initialization</em> and since I can't think of any way to create a thread until you get to <em>dynamic-initialization</em>, such an early initialization would also guarantee the constructor would get called a single time.</p> <p><strong>Update</strong></p> <p>So, in respect to calling the <code>some_type</code> constructor for <code>the_const_thingy</code>, your code is correct according to the rules.</p> <p>This leaves the issue about overwriting the reference which is definitely not covered by the spec. That said, if you are willing to assume that references are implemented via pointers (which I believe is the most common way to do that), then all you are going to do is overwrite a pointer with the value that it already holds. So my take is that this should be safe in practice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload