This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ case value question


I'm new to this list but not to gcc. I'm not sure that this is the proper forum, but if not, perhaps someone will steer me to the proper list. I didn't want to submit this to bugzilla yet as I'm not sure whether my constructs in this case are valid C++.

I've tried both 3.3.1 and 3.4.1 for m68k-elf and get different results. Here is a test fragment:

struct sTestStruct {
                     static int const Constant = 1;
                     enum { EnumConstant };
                   };
         sTestStruct TestStruct;
volatile sTestStruct TestStructVolatile;
bool TestFunction( int TestVariable )
{
  switch ( TestVariable ) // This always works and should.
    {
      case sTestStruct::Constant:     return true;
      case sTestStruct::EnumConstant: return true;
    }
  switch ( TestVariable ) // This works in 3.3.1 but not 3.4.1.
    {
      case TestStruct.Constant:     return true;
      case TestStruct.EnumConstant: return true;
    }
  switch ( TestVariable ) // This doesn't work, should it?
    {
      case TestStructVolatile.Constant:     return true;
      case TestStructVolatile.EnumConstant: return true;
    }
  return false;
}

When compiled with 3.3.1 using the command line "m68k-elf-gcc -c test.cpp", I get:

test.cpp: In function `bool TestFunction(int)':
test.cpp:21: error: case label does not reduce to an integer constant
test.cpp:22: error: case label does not reduce to an integer constant

When compiled with 3.4.1 using the same command line, I get:

test.cpp: In function `bool TestFunction(int)':
test.cpp:16: error: `TestStruct' cannot appear in a constant-expression
test.cpp:16: error: `.' cannot appear in a constant-expression
test.cpp:17: error: `TestStruct' cannot appear in a constant-expression
test.cpp:17: error: `.' cannot appear in a constant-expression
test.cpp:21: error: `TestStructVolatile' cannot appear in a constant-expression
test.cpp:21: error: `.' cannot appear in a constant-expression
test.cpp:22: error: `TestStructVolatile' cannot appear in a constant-expression
test.cpp:22: error: `.' cannot appear in a constant-expression

These results illustrate two separate issues. 

First, should the compiler accept a constant declaration which is imbedded in a volatile definition as a reasonable case value? This is especially interesting in the case of the enum since its value cannot possibly be construed as variable.

Second, should the form TestStruct.Constant or TestStruct.EnumConstant be acceptable as a case value? It was in 3.3.1 but is no longer in 3.4.1.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]