<html>
  <head>
    <title>N2546 Removal of auto as a storage-class specifier</title>
    <base href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <style type="text/css">
      /* <![CDATA[*/
        address {text-align: right}
        p {text-align:justify}
        li {text-align:justify}
        ins {background-color:#FFFF99}
        del {background-color:#FF9999}
     /* ]]> */
    </style>
  </head>

<body>
Document Number: N2546<br/>
2008-02-28<br/>
Daveed Vandevoorde &lt;daveed@vandevoorde.com><br/>
Jens Maurer &lt;Jens.Maurer@gmx.net><br/>

<h1>Removal of auto as a storage-class specifier</h1>

The Core Working Group discussed N2337 "The Syntax of auto Declarations"
by Daveed Vandevoorde in Kona.  The consensus was to remove the use of
"auto" as a storage class specifier entirely.  This paper presents
proposed changes to the working paper to implement that approach,
resolving core issue 629.


<h2>Proposed wording changes</h2>

Remove 3.7 basic.stc paragraph 3:
<blockquote>
<del>The storage class specifiers <code>static</code> and
<code>auto</code> are related to storage duration as described
below.</del>
</blockquote>

Change 3.7.2 basic.stc.auto paragraph 1 as indicated:
<blockquote>
Local objects explicitly declared <del><code>auto</code> or</del>
<code>register</code> or not explicitly declared <code>static</code>
or <code>extern</code> have automatic storage duration. The storage
for these objects lasts until the block in which they are created
exits.
</blockquote>

Change 5.3.4 paragraph 2 as indicated:
<blockquote>
If the <code>auto</code> <em>type-specifier</em> appears in the
<em>type-specifier-seq</em> of a <em>new-type-id</em> or
<em>type-id</em> of a <em>new-expression</em>, <del>the
<em>type-specifier-seq</em> shall contain no other
<em>type-specifier</em>s except <em>cv-qualifier</em>s, and</del> the
<em>new-expression</em> shall contain a <em>new-initializer</em> of
the form
<pre>
       ( assignment-expression )
</pre>
</blockquote>

Change 6.4 paragraph 2 as indicated:
<blockquote>
... If the auto type-specifier appears in the
<em>type-specifier-seq</em>, <del>the type-specifier-seq shall contain no
other
<em>type-specifier</em>s except <em>cv-qualifier</em>s, and</del> the
type of the identifier being declared is deduced from the
<em>assignment-expression</em> as described in 7.1.6.4 dcl.spec.auto.
</blockquote>


Add a grammar production to the end of 7.1.6 dcl.type paragraph 1:
<blockquote>
<pre>
type-specifier-seq:
       type-specifier type-specifier-seq<sub>opt</sub>
</pre>
</blockquote>


In 7.1.6 dcl.type paragraph 2, change as indicated:
<blockquote>
As a general rule, at most one <em>type-specifier</em> is allowed in the
complete <em>decl-specifier-seq</em> of a declaration <ins>or in a
<em>type-specifier-seq</em></ins>. The only exceptions to this rule are the
following:  ...
<ul>
<li><del>auto can be combined with any type specifier except itself.</del></li>
</ul>
</blockquote>

Change 7.1.6.4 dcl.type.auto paragraphs 1-3 as indicated:

<blockquote>
<p>
<del>
The <code>auto</code> <em>type-specifier</em> has two meanings
depending on the context of its use. In a <em>decl-specifier-seq</em>
that contains at least one <em>type-specifier</em> (in addition to
auto) that is not a <em>cv-qualifier</em>, the <code>auto</code>
<em>type-specifier</em> specifies that the object named in the
declaration has automatic storage duration. The
<em>decl-specifier-seq</em> shall contain no
<em>storage-class-specifier</em>s. This use of the <code>auto</code>
specifier shall only be applied to names of objects declared in a
block (6.3) or to function parameters (8.4).
</del>
</p>

<p>
<del>Otherwise (<code>auto</code> appearing with no type specifiers other than
cv-qualifiers), the</del> <ins>The</ins> <code>auto</code> <em>type-specifier</em> signifies
that the type of an object being declared shall be deduced from its
initializer. The name of the object being declared shall not appear in
the initializer expression. 
</p>

<p>
<del>This use of auto</del> <ins>The <code>auto</code>
<em>type-specifier</em></ins> is allowed when declaring
objects in a block (6.3), in namespace scope (3.3.5), and in a
<em>for-init-statement</em> (6.5.3). The <em>decl-specifier-seq</em>
shall be followed by one or more init-declarators, each of which shall
have a non-empty initializer of either of the following forms:
<pre>
        = assignment-expression
        ( assignment-expression )
</pre>
<pre>
  [ Example:
     auto x = 5;                     // OK: x has type int
     const auto *v = &x, u = 6;      // OK: v has type const int*, u has type const int
     static auto y = 0.0;            // OK: y has type double
     <del>static auto int z;         // error: auto and static conflict</del>
     auto int r;                     // <del>OK: r has type int</del><ins>error: auto is not a storage-class-specifier</ins>
   -- end example ]
</pre>

</blockquote>


Remove the grammar production from 8.1 dcl.name paragraph 1:
<blockquote>
<pre>
<del>
type-specifier-seq:
       type-specifier type-specifier-seq<sub>opt</sub>
</del>
</pre>
</blockquote>


Change 8.3 dcl.meaning paragraph 2 as indicated:

<blockquote>
<del>An auto,</del> <ins>A</ins> static, extern, register, mutable,
friend, inline, virtual, or typedef specifier applies directly to each
<em>declarator-id</em> in an <em>init-declarator-list</em>; the type
specified for each <em>declarator-id</em> depends on both the
<em>decl-specifier-seq</em> and its <em>declarator</em>.
</blockquote>

Change 8.3.4 dcl.array paragraph 1 as indicated:
<blockquote>

In a declaration T D where D has the form
<pre>
       D1 [ constant-expression<sub>opt</sub> ]
</pre>
and the type of the identifier in the declaration T D1 is
"<em>derived-declarator-type-list</em> T," then the type of the identifier of D
is an array type; if the type of the identifier of D contains the
<code>auto</code> <del>type deduction</del> <em>type-specifier</em>,
the program is ill-formed. ...
</blockquote>

Change 9.2 class.mem paragraph 6 as indicated:
<blockquote>
A member shall not be declared <del>to have automatic storage duration
(auto, register) or </del> with the <code>extern</code> <ins>or
<code>register</code></ins> <em>storage-class-specifier</em>s.
</blockquote>

Change the example in 9.8 class.local paragraph 1 as indicated:
<blockquote>
[ Example:
<pre>
  int x;
  void f()
  {
      static int s ;
      int x;
      extern int g();
      struct local {
      int g() { return    x; }    // error: x <del>is auto</del> <ins>has automatic storage duration</ins>
      int h() { return    s; }    // OK
      int k() { return    ::x; }  // OK
      int l() { return    g(); }  // OK
      };
       // ...
  }
  local* p = 0;                         // error: local not in scope
</pre>
-- end example ]
</blockquote>


Add an element to C.1.5 diff.dcl (not shown in bold here):

<blockquote>
7.1.6.4 dcl.type.auto
<p>
<strong>Change:</strong> The keyword <code>auto</code> cannot be used
as a storage class specifier.
<p>
Example:
<pre>
   void f()
   {
     auto int x;     // valid C, invalid C++
   }
</pre>

<strong>Rationale:</strong> Allowing the use of <code>auto</code> to
deduce the type of a variable from its initializer results in
undesired interpretations of <code>auto</code> as a storage class
specifier in certain contexts.<br/>
<strong>Effect on original feature:</strong> Deletion of semantically
well-defined feature.<br/>
<strong>Difficulty of converting:</strong> Syntactic transformation.<br/>
<strong>How widely used:</strong> Rare.
</blockquote>


In the index, remove the entries for
<blockquote>
<pre>
<del>
auto
    destruction of,
initialization,
    auto
</del>
</pre>
</blockquote>

Change the index entry for 

<blockquote>
<pre>
storage duration, 60
     <del>auto</del><ins>automatic</ins>, 61
</pre>
</blockquote>

</body>
</html>
