title: Can a class template explicit specialization also declare something else?
body: <p>It would be nice if this code were invalid. But it's conceptually sound, and GCC <a href="http://ideone.com/kO2aC" rel="nofollow">accepts it</a> although Comeau doesn't:</p>
  
  <pre><code>template&lt; typename &gt; struct t;
  
  template&lt;&gt; struct t&lt; int &gt; {} r; // Bad declarator! Don't pee on the carpet!
  </code></pre>
  
  <p>(<strong>Edit:</strong> the above compiles but <code>r</code> seems no to be declared <a href="http://ideone.com/KkV1n" rel="nofollow">into any scope</a>, so it is essentially ignored.)</p>
  
  <p>Explicit specializations populate a kind of nether region between templates and classes. The type declared by an explicit specialization is complete once it is defined. From the compiler's standpoint, it is not a template. If it were a parameterized template, declaring an object would be impossible. Consider §14/3:</p>
  
  <blockquote>
    <p>In a template-declaration, explicit specialization, or explicit instantiation the init-declarator-list in the dec- laration shall contain at most one declarator. When such a declaration is used to declare a class template, no declarator is permitted.</p>
  </blockquote>
  
  <p>What does "is used to declare a class template" mean? Clearly a primary template declares a class template. And a partial specialization does too, according to §14.5.5/1 (FDIS numbers):</p>
  
  <blockquote>
    <p>A template declaration in which the class template name is a simple-template-id is a partial specialization of the class template named in the simple-template-id.</p>
  </blockquote>
  
  <p>When it comes to explicit specializations, though, the Standard speaks in terms of a declaration preceded by the token sequence <code>template&lt;&gt;</code>. It <em>looks</em> like a template and it names a template-name, but it doesn't seem to declare a template.</p>
  
  <p>The really bizarre thing is that §14/3 restricts the number of declarators to "at most one." A function template declaration, explicit specialization or instantiation must have exactly one declarator. Any declaration involving a class template must have exactly zero… except explicit specialization, which seems to fall through the cracks. Faithfully, GCC <a href="http://ideone.com/G5ZEg" rel="nofollow">refuses to allow</a> </p>
  
  <pre><code>template&lt;&gt; struct t&lt; int &gt; {} r, s; // Offer valid one per specialization.
  </code></pre>
  
  <p>I tend to agree with GCC's interpretation, nonsense as it may be. Unfortunately, it may be <a href="http://gcc.gnu.org/bugzil" rel="nofollow">inhibiting</a> its ability to detect missing semicolons. Please, let the number of allowed declarators be exactly zero!</p>