11

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.

Community
  • 1
  • 1
jakar
  • 1,031
  • 1
  • 11
  • 22

1 Answers1

11

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").

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Thanks. That's what I had thought. I needed someone to verify that I wasn't missing something. – jakar Oct 13 '11 at 17:31