title: constructor execution sequence/order: dependent initialization of static variable (class instance) in a function
body: <p>For the following code segment:</p>
  
  <pre><code>class Bar {
  public:
      int x;
      int y;
      Bar(int _x, int _y) {  /* some codes here */ ...}
  };
  class Foo {
  public:
      int x;
      int y;
      int z;
      Foo(Bar b):x(b.x), y(b.y)
      {
          z = someFunction(x, y);
      }
  };
  
  void f(int x, int y)
  {
       Bar b(x, y);
       static Foo x(b);
  }
  int main()
  {
       f(2, 3);
  }
  </code></pre>
  
  <p>In my mind, a static variable inside a function should be initialized even before <code>main()</code>.  However, the static variable <code>x</code> of type <code>Foo</code> depends on a local variable <code>b</code> of type <code>Bar</code>.</p>
  
  <p>The questions are:</p>
  
  <p>1) When does the constructor of <code>x</code> execute?  i.e. Are <code>x</code> initialized with the first invocation of the local variable <code>b</code>?  I don't want some particular result of some special compiler case, but want to know if it is well-defined in the C++ language.</p>
  
  <p>2) Is it a valid program?</p>
  
  <p>3) It it a a good practice?</p>