如果我将变量重新定义为auto,并且推导出的类型相同,它是否格式正确? [英] Is it well-formed, if I redefine a variable as auto, and the deduced type is the same?

查看:25
本文介绍了如果我将变量重新定义为auto,并且推导出的类型相同,它是否格式正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个片段:

int a;
extern int b;
auto b = a;

它是否格式良好?Clang 成功编译了它,但 GCC 和 MSVC 没有.

Is it well-formed? Clang successfully compiles it, but GCC and MSVC don't.

(当我回答如何声明和定义具有推导类型的静态成员?)

推荐答案

Tl;DR;

clang 是正确的,逻辑是 [dcl.spec.auto] 允许这样做,并限制推导出的返回类型 [dcl.spec.auto]p11 已添加,否则没有限制,因此这不受变量情况的限制.

Tl;DR;

clang is correct, the logic is that this is allowed by [dcl.spec.auto] and to restrict this for deduced return types [dcl.spec.auto]p11 was added otherwise there is no restriction and therefore this is not restricted for the variables case.

参见我在副本中更完整的答案

这篇关于如果我将变量重新定义为auto,并且推导出的类型相同,它是否格式正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆