如果我将变量重新定义为auto,并且推导的类型相同,它的格式是否正确? [英] Is it well-formed, if I redefine a variable as auto, and the deduced type is the same?
本文介绍了如果我将变量重新定义为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.
(当我回答推荐答案
clang是正确的,逻辑是 clang is correct, the logic is that this is allowed by 请参阅我的重复中更完整的答案 这篇关于如果我将变量重新定义为auto,并且推导的类型相同,它的格式是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Tl; DR;
[dcl.spec.auto]
允许这样做,并将其限制为推导的返回类型Tl;DR;
[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.
查看全文