<html>
<head><title>N2713 - Allow auto for non-static data members</title></head>
<body>
<table border=0>
<tr>
  <td><b>Doc No:</b></td>
  <td>N2713 = 08-0223</td>
</tr>
<tr>
  <td><b>Date:</b></td>
  <td>2008-08-04</td>
</tr>
<tr>
  <td><b>Reply to:</b>&nbsp;</td>
  <td>Bill Seymour &lt;stdbill.h@pobox.com&gt;</td>
</tr>
</table>

<center>

<h1>Allow <tt>auto</tt> for non-static data members</h1>
<h3>Bill Seymour</h3>
</center>

<p><hr size=5>

<h2>Rationale</h2>

An early version of the non-<tt>static</tt> data member initializer paper
deleted &ldquo;static&rdquo; from 7.1.6.4p4, which lists the places where
the <tt>auto</tt> <i>type-specifier</i> may appear.

<p>One national body disliked allowing
<nobr>non-<tt>static</tt>s to be declared <tt>auto</tt>.</nobr>
From an e-mail to the author:

<blockquote>
<blockquote>
<pre>
template&lt; class T &gt;
struct MyType : T {
  auto data = func();
  static const size_t erm = sizeof(data);
};
</pre>
</blockquote>

In order to determine the layout of X, we now have 2-phase name lookup and ADL.
Note that func could be either a type or a function; it may be found in T,
the namespace of MyType, the associated namespace(s) of T when instantiated,
the global namespace, an anonymous namespace, or any namespaces subject to
a using directive.  With care we could probably throw some concept_map lookup
in for luck.

<p>Depending on the order of header inclusion I might even get different results
for ADL, and break the One Definition Rule - which is not required to be diagnosed.
</blockquote>

Because of this controversy, the current version of the initializer paper,
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2712">N2712</a>, retains the &ldquo;static&rdquo;.

<p>Recently, it was pointed out on <i>comp.lang.c++.moderated</i> that
one can get the same effect anyway, just with uglier code, using
<tt>decltype</tt>.  Because of that, the author believes that the
objection to <tt>auto</tt> has softened.

<p>This paper suggests deleting the &ldquo;static&rdquo;.
If <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2712">N2712</a>
is not accepted for C++0X, this paper is moot.

<p><hr size=5>

<h2>
  Suggested change to the Working Paper,
  <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2691">N2691</a>
  as modified by <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2712">N2712</a>
</h2>

<h4>7.1.6.4 <tt>auto</tt> specifier [dcl.spec.auto]</h4>

<p>Delete &ldquo;static&rdquo; from paragraph 4:
<blockquote>
The <tt>auto</tt> <i>type-specifier</i> can also be used in declaring an object
in the <i>condition</i> of a selection statement (6.4) or an iteration statement (6.5),
in the <i>type-specifier-seq</i> in a <i>new-type-id</i> (5.3.4), and in declaring
a <del>static</del> data member with a <nobr><i>brace-or-equal-initializer</i></nobr>
that appears within the <nobr><i>member-specification</i></nobr> of a class definition (9.4.2).
</blockquote>

<p><hr size=5>
</body>
</html>
