开发者

Is it safe to disable MSVC warning C4482?

开发者 https://www.devze.com 2023-04-13 00:37 出处:网络
While qualifying an enumeration value with the name of the enumeration is not valid C++03, it is valid C++11, from what I understand. Despite this, MSVC 10 generates warning C4482 for the following:

While qualifying an enumeration value with the name of the enumeration is not valid C++03, it is valid C++11, from what I understand. Despite this, MSVC 10 generates warning C4482 for the following:

enum E { A, B };

int i = E::A;  // warning C4482 (but valid C++11?)

Since much of our code uses C++11 features (especially lambdas), it seems safe to disable this warning. Am I right that the code is valid C++11?

Note: I did not write the code in question, and I would prefer to not go through and change every occurrence of this.

Edit: Added some relevant links.

  • MSDN page开发者_开发技巧 for the warning.
  • Another question about the warning. The question and answers all seem to reference C++03.


Since much of our code uses C++11 features (especially lambdas), it seems safe to disable this warning.

If you're already relying on C++11 features, then yes. C++11 does allow you to use regular enums scoped by the enumeration's name. Microsoft had this as an extension for some time, so they issued a warning about the non-standard behavior.

So you can disable it.

Note that older compilers like VC2010, instead of warning, did raise compile error C2653 (with message "... is not a class or namespace name").

0

精彩评论

暂无评论...
验证码 换一张
取 消