TreDubZedd
TreDubZedd

Reputation: 2556

How do I ensure Visual C++ doesn't allow scoped enum access?

I have a C++ codebase which is compiled using various versions of GCC and Visual Studio (2017). Some of our programmers (with C# backgrounds) tend to fully qualify the name of an enum (e.g. ClassName::EnumName::EnumValue vs. the proper ClassName::EnumValue). Visual Studio seems to be fine with this usage (even though the enum is not defined as enum class, per C++11), but GCC (correctly) errors out.

What can I do to make Visual Studio give errors similar to GCC, in this case?

Edit: I should note that the GCC version we require tends to be pretty old (before 6.1)

Upvotes: 0

Views: 111

Answers (1)

NathanOliver
NathanOliver

Reputation: 180500

You are not going to be able to make MSVS cause a compiler error. With the introduction of scoped enums it became legal to to refer to a non scoped enumeration using the enum name. That means ClassName::EnumName::EnumValue and ClassName::EnumValue are both legal in C++11 and above.

MSVC 2017 only supports /std:[c++14|c++17|c++latest] for it's C++ standard to compile against so it will always be legal to ClassName::EnumName::EnumValue.

This will probably lead to more issues if you are not going to compile against C++14 with your other compilers as the MSVS people might use other C++14 and above features that wont compile in C++98/03/11.

Upvotes: 1

Related Questions