Scoped enums in switch

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:

#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;

}

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)

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

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Quote:

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today