'warning C4709: comma operator within array index expression' - but no comma to be seen anywhere!

三世轮回 提交于 2021-02-18 20:54:01

问题


Take this little example code:

struct Test{
    operator int() const{
        return 0;
    }
};

Test test(){
    return Test();
}

int main(){
    int arr[10];
    arr[test()] = 5;
}

Compiling under Visual Studio 2010 with /W4 generates said warning. Interestingly, if I add but a simple default constructor, the warning suddenly vanishes. Also, it only works in that constellation. If I remove the function call or don't return a user-defined type, the warning disappears. Also, as expected, GCC doesn't produce such a warning.

So, can I take this warning with the above code as a bug in Visual Studio or is there more to it than seems? Would be very surprising though, to say the least.


Edit: Created a bug report on Microsoft Connect.


回答1:


Definitely it is a bug - misleading warning.



来源:https://stackoverflow.com/questions/6012068/warning-c4709-comma-operator-within-array-index-expression-but-no-comma-to

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