Is `auto int i` valid C++0x?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 07:12:11

问题


In answering this question the question arose as to whether the traditional C meaning of the keyword auto (automatic storage) is still valid in C++0x now that it means type deduction.

I remember that the old meaning of auto should remain where relevant but others disagreed.

auto char c = 42; // either compilation error or c = '*'

Looking at compilers I see the current division.

  1. Old meaning of auto is no longer allowed
    • VS10
    • g++
  2. Old meaning of auto is used where relevant
    • Comeau

Do you know which is the correct behaviour?


回答1:


No, it is not. In fact, §7.1.6.​4/3 gives the following 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
auto int r; // error: auto is not a storage-class-specifier

As you can see, it results in an error. §7.1.6.​5 pretty much seals the deal with:

A program that uses auto in a context not explicitly allowed in this section is ill-formed.



来源:https://stackoverflow.com/questions/2847734/is-auto-int-i-valid-c0x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!