根据提交的论文,N3638,明确有效 .
相关片段:
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
auto f() -> int; // OK: f returns int
auto g() { return 0.0; } // OK: g returns double
auto h(); // OK, h's return type will be deduced when it is defined
然而它继续说:
如果需要具有未减弱占位符类型的实体类型来确定表达式的类型,则程序格式错误 . 但是一旦在函数中看到了return语句,从该语句推导出的返回类型可以在函数的其余部分中使用,包括在其他return语句中 .
auto n = n; // error, n's type is unknown
auto f();
void g() { &f; } // error, f's return type is unknown
auto sum(int i) {
if (i == 1)
return i; // sum's return type is int
else
return sum(i-1)+i; // OK, sum's return type has been deduced
}
因此,在定义之前使用它的事实会导致错误 .