2 Replies Latest reply: Apr 2, 2014 4:00 AM by jthackray RSS

    enum class not supported for switch() statement in 12.4 beta?

    jthackray

      Hi fellow 12.4 beta testers,

       

      It would appear "enum class" isn't supported for switch() statements in the 12.4 beta. This compiles fine under clang and g++. Will this be fixed for the final release? This currently causes compile errors for us, since __cplusplus >= 201103L evaluates to true, so our code uses "enum class" instead of plain "enum". It looks like the C++11 standard says it should be supported:

         Switching on enum class in C++ 0x - Stack Overflow

       

      Many thanks,

      Jonathan.

       

      $ cat test.cpp

      #include <iostream>

       

      enum class Ternary { KnownFalse = 0, KnownTrue = 1, Unknown = 2 };

       

      int main( void )

      {

         Ternary foo;

         switch ( foo ) {

            case Ternary::KnownTrue:

            case Ternary::KnownFalse:

            case Ternary::Unknown:

               std::cout << "Success\n";

         }

      }

       

      $ clang++ -std=c++11 test.cpp

      $ g++ -std=c++11 test.cpp

      $ /opt/SolarisStudio12.4-beta_mar14-solaris-x86/bin/CC -std=c++11 test.cpp

      "test.cpp", line 8: Error: Cannot use Ternary to initialize integral type.

      "test.cpp", line 8: Error: Switch selection expression must be of an integral type.

      "test.cpp", line 9: Error: An integer constant expression is required for a case label.

      "test.cpp", line 10: Error: An integer constant expression is required for a case label.

      "test.cpp", line 11: Error: An integer constant expression is required for a case label.

      5 Error(s) detected.