Title
Consistency of auto in multiple-declarator declarations
Status
cd3
Section
9.2.9.7 [dcl.spec.auto]
Submitter
Richard Smith

Created on 2011-08-16.00:00:00 last changed 130 months ago

Messages

Date: 2012-02-15.00:00:00

[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]

Date: 2011-08-15.00:00:00

Proposed resolution (August, 2011):

Move the example in 9.2.9.7 [dcl.spec.auto] paragraph 7 into that of paragraph 6 and change paragraph 7 as follows:

...[Example:

  auto x1 = { 1, 2 };   // decltype(x1) is std::initializer_list<int>
  auto x2 = { 1, 2.0 }; // error: cannot deduce element type

  const auto &i = expr;

The type of i is the deduced type of the parameter u in the call f(expr) of the following invented function template:

  template <class U> void f(const U& u);

end example]

If the list of declarators init-declarator-list contains more than one declarator init-declarator, the type of each declared variable is determined as described above. If the type deduced for the template parameter U that replaces the occurrence of auto is not the same in each deduction, the program is ill-formed.

[Example:

  const auto &i = expr;

The type of i is the deduced type of the parameter u in the call f(expr) of the following invented function template:

  template <class U> void f(const U& u);
  auto x = 5, *y = &x;       // OK: auto is int
  auto a = 5, b = { 1, 2 };  // error: different types for auto

end example]

Date: 2011-08-16.00:00:00

The intent of 9.2.9.7 [dcl.spec.auto] paragraph 7 appears to have been that the type represented by auto should be the same for each declarator in the declaration. However, the current wording does not achieve that goal. For example, in

    auto a = 0, b = { 1, 2, 2 };

the auto specifier represents int in the first declarator and std::initializer_list<int> in the second. (See also issue 1265.)

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2012-11-03 00:00:00adminsetstatus: dr -> drwp
2012-02-27 00:00:00adminsetmessages: + msg3805
2012-02-27 00:00:00adminsetstatus: ready -> dr
2011-09-06 00:00:00adminsetmessages: + msg3457
2011-08-16 00:00:00admincreate