title: auto and decltype in for loop initialization
body: <p>I've been happily iterating like </p>
  
  <pre><code>for( auto n = object.get_size(), i = decltype( n )( 0 ); 
       i &lt; n; 
       ++i 
  ) { ... } 
  </code></pre>
  
  <p>to get all the types automagically right. Using g++ 4.7.1 there was no problem, but with version 4.7.0 I got errors. Since 4.7.1 is pretty new, I want to know which version implements the bug and which one the standard. Also, 4.7.0 (as well as 4.6.3 with std=c++0x) only complains when used in conjunction with template, and generates different errors in different usages. See the following code:</p>
  
  <pre><code>/* test.cxx */
  #ifdef V1
  
  #ifdef GENERIC
  template&lt; class T &gt;
  void do_some( T obj ) {
      for( auto n = obj, i = decltype( n )( 0 );
               i &lt; n; ++i ) { }
  }
  #endif
  
  #ifdef SPECIFIC
  void do_some( int obj ) {
      for( auto n = obj, i = decltype( n )( 0 );
               i &lt; n; ++i ) { }
  }
  #endif
  
  #endif
  
  #ifdef V2
  template&lt; class T &gt;
  class foo {
      T member;
  public:
      foo( T stuff ) : member( stuff ) {}
      T get_member() { return member; }
  };
  
  #ifdef GENERIC
  template&lt; class T &gt;
  void do_some( T obj ) {
      for( auto n = obj.get_member(), i = decltype( n )( 0 );
               i &lt; n; ++i ) { }
  }
  #endif
  
  #ifdef SPECIFIC
  void do_some( foo&lt; int &gt; obj ) {
      for( auto n = obj.get_member(), i = decltype( n )( 0 );
               i &lt; n; ++i ) { }
  }
  #endif
  
  #endif
  
  
  
  int main() {
      #ifdef V1
      int foo_inst = 10;
      #endif
  
      #ifdef V2
      foo&lt; int &gt; foo_inst( 10 );
      #endif
  
      do_some( foo_inst );
  
      return 0;
  }
  </code></pre>
  
  <p>and the output of g++ version 4.7.0</p>
  
  <pre><code>$ g++-4.7 -DV1 -DGENERIC -std=c++11 test.cxx 
  test.cxx: In function ‘void do_some(T)’:
  test.cxx:7:42: error: inconsistent deduction for ‘auto’: ‘T’ and then ‘decltype (n)’
  $ g++-4.7 -DV1 -DSPECIFIC -std=c++11 test.cxx 
  /* compiles fine */
  $ g++-4.7 -DV2 -DGENERIC -std=c++11 test.cxx 
  test.cxx: In function ‘void do_some(T)’:
  test.cxx:35:55: error: variable ‘auto n’ with ‘auto’ type used in its own initializer
  $ g++-4.7 -DV2 -DSPECIFIC -std=c++11 test.cxx 
  /* compiles fine */
  </code></pre>