Why old usage (c++03) of auto does not compile under C++11?

谁说胖子不能爱 提交于 2019-12-23 12:47:56

问题


I know that auto has a little usage before because it is the default for variables (opposite to static) - see question Consider however valid C++03 code where, maybe for self-explanatory, this keyword was used:

auto int foo2 = 8;

It compiles under C++03, and does not compile under C++11. Is there any reason for not being back-compatible with C++03? What was the source of standard committee opinion that this keyword was not used? Are there any statistics of keyword usage?

BTW i tested with gcc - maybe this is a compiler bug?


回答1:


It was known that this breaks compatibility and is mentioned in Appendix C 2.3 Clause 7 of the standard. Given how useless auto has been and that it is really easy to fix the cost was deemed acceptable.

As for keyword statistics: Some companies with huge code-bases are on the committee, they probably know if it was acceptable, but I could not dig up any full statistics.

I did some standards archeology and the oldest paper that talks about auto seems to be N1478, which refers to a reflector message for the first discussing of auto (all later papers don't talk about breaking compatibility or reasoning).




回答2:


This was removed from C++11 because they have a new use for auto, and it would be confusing to allow auto auto foo2 = 8; to work. Nothing of significance is lost by removing this ancient and pointless declaration.



来源:https://stackoverflow.com/questions/12093717/why-old-usage-c03-of-auto-does-not-compile-under-c11

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