Visual Studio warning C4334 on assignment but not on initialization

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 17:43:48

问题


Why i got warning on this code:

#include <cstdint>

int main()
{
    int i = 1;
    int64_t i64;
    i64 = 1 << i;
}

warning C4334: '<<' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

but not on this:

#include <cstdint>

int main()
{
    int i = 1;
    int64_t i64 = 1 << i;
}

? Tested on vs2013/2015.


回答1:


I see the same discrepancy with vs2012. I don't think that there is a good reason for it - hopefully the warning will be emitted in both cases in a newer version of Visual C++.




回答2:


MSVS 2015 Upd.2: Second case (on initialization) will trigger C4334 warning.



来源:https://stackoverflow.com/questions/31558314/visual-studio-warning-c4334-on-assignment-but-not-on-initialization

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