Title
Use of auto as a template-argument
Status
cd2
Section
9.2.9.6 [dcl.spec.auto]
Submitter
John Spicer

Created on 2007-03-09.00:00:00 last changed 143 months ago

Messages

Date: 2010-03-15.00:00:00

[Voted into WP at March, 2010 meeting.]

Date: 2009-10-15.00:00:00

Proposed resolution (October, 2009):

Change 9.2.9.6 [dcl.spec.auto] paragraph 3 as follows:

...The auto shall appear as one of the decl-specifiers in the decl-specifier-seq and the decl-specifier-seq shall be followed by one or more init-declarators, each of which shall have a non-empty initializer.
Date: 2008-02-15.00:00:00

Notes from the February, 2008 meeting:

It was agreed that the example should be ill-formed.

Date: 2007-03-09.00:00:00

The auto specifier can be used only in certain contexts, as specified in 9.2.9.6 [dcl.spec.auto] paragraphs 2-3:

Otherwise (auto appearing with no type specifiers other than cv-qualifiers), the auto type-specifier 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.

This use of auto is allowed when declaring objects in a block (8.4 [stmt.block]), in namespace scope (6.4.5 [basic.scope.namespace]), and in a for-init-statement (8.6.4 [stmt.for]). The decl-specifier-seq shall be followed by one or more init-declarators, each of which shall have a non-empty initializer of either of the following forms:

    = assignment-expression
    ( assignment-expression )

It was intended that auto could be used only at the top level of a declaration, but it is not clear whether this wording is sufficient to forbid usage like the following:

    template <class T> struct A {};
    template <class T> void f(A<T> x) {}

    void g()
    {
        f(A<short>());

        A<auto> x = A<short>();
    }
History
Date User Action Args
2010-03-29 00:00:00adminsetmessages: + msg2689
2010-03-29 00:00:00adminsetstatus: ready -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2351
2009-11-08 00:00:00adminsetstatus: drafting -> ready
2008-03-17 00:00:00adminsetmessages: + msg1605
2008-03-17 00:00:00adminsetstatus: open -> drafting
2007-03-09 00:00:00admincreate