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

查看:104
本文介绍了如果我将变量重新定义为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]允许这样做,并将其限制为推导的返回类型

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天全站免登陆