Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ben3
Beginner
151 Views

Scoped enums in switch

Hi,

I can't seem to get scoped enums to work as case labels in a switch block in the Linux compiler. The following compiles fine on Windows but failed on Linux:

[cpp]

#include <iostream>


int main ( int argc, char * argv [] ) {

  enum class scoped_enum {

    AA, BB, CC, DD

  };

  scoped_enum test (scoped_enum::AA);

  switch (test) {

  case scoped_enum::AA:

    std::cout << "AA" << std::endl;

    break;

  case scoped_enum::BB:

    std::cout << "BB" << std::endl;

    break;

  case scoped_enum::CC:

    std::cout << "CC" << std::endl;

    break;

  case scoped_enum::DD:

    std::cout << "DD" << std::endl;

    break;

  }

  return 0;

}

[/cpp]

[plain]

bmenadue@weyl ~/bmenadue/Code/testing>icpc --version

icpc (ICC) 13.1.1 20130313

Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

bmenadue@weyl ~/bmenadue/Code/testing>icpc test.cpp -std=c++0x

test.cpp(12): error: expression must have integral or unscoped enum type

    case scoped_enum::AA:

         ^

test.cpp(15): error: expression must have integral or unscoped enum type

    case scoped_enum::BB:

         ^

test.cpp(18): error: expression must have integral or unscoped enum type

    case scoped_enum::CC:

         ^

test.cpp(21): error: expression must have integral or unscoped enum type

    case scoped_enum::DD:

         ^

compilation aborted for test.cpp (code 2)

[/plain]

Is this a compiler bug, or am I doing something wrong (thought it would be a common issue but I couldn't find any other threads about it)?

Thanks,

Ben

0 Kudos
2 Replies
SergeyKostrov
Valued Contributor II
151 Views

>>...Is this a compiler bug... Please take a look at a similar thread and Judith provided a description of the problem ( just a couple of days ago ): Forum Topic: Status of strongly typed enums support in version 13.0 Web-link: software.intel.com/en-us/forums/topic/326793
Ben3
Beginner
151 Views

Sergey Kostrov wrote:

Please take a look at a similar thread and Judith provided a description of the problem...

Ah, thanks Sergey. That's it; looks like I missed that thread when I was searching.

I'll just use an unscoped enum until it's fixed.

Cheers,
Ben

Reply