Failing to get warning C4482 in VS-2017

Loki 21 Reputation points
2021-01-03T08:33:39.98+00:00

In Visual Studio 2017 (15.9.11) I fail to get warning C4482 on the code below.

I also tried to set:

  • Disable Language Extensions - Yes
  • Conformance mode - Yes
  • EnableAllWarning (/Wall)
  • using pragma (and also through project settings) to force this warning as error

Any idea why it does not work?

// Trying also to force the warning as an error
#pragma warning(error : 4482)

class CA
{
    enum COLOR
    {
        RED = 0
    };

    void foo()
    {
        COLOR c = CA::COLOR::RED;   // Expecting warning C4482
        c = COLOR::RED;             // Expecting warning C4482
    }
};
Developer technologies | C++
Developer technologies | Visual Studio | Other
{count} votes

Accepted answer
  1. David Lowndes 4,726 Reputation points
    2021-01-03T11:01:01.337+00:00

    Presumably something changed in the C++ standard.
    The documentation notes:

    "This warning is not generated by Visual C++ compilers that support C++11."


1 additional answer

Sort by: Most helpful
  1. Igor Tandetnik 1,116 Reputation points
    2021-01-03T14:57:51.23+00:00

    It's valid, standard-conforming code, as of C++11 which added the following paragraph:

    [basic.lookup.qual]/5 A name prefixed by a nested-name-specifier that nominates an enumeration type shall represent an enumerator of that enumeration.

    To remove all doubt, there's a (non-normative) example in [dcl.enum]:

    enum direction { left=’l’, right=’r’ };
    
    void g() {
      direction d; // OK
      d = left; // OK
      d = direction::right; // OK
    }
    
    enum class altitude { high=’h’, low=’l’ };
    
    void h() {
      altitude a; // OK
      a = high; // error: high not in scope
      a = altitude::low; // OK
    }
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.