public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35205]  New: Structure enum wrongly interpreted as a variable in switch case.
@ 2008-02-15  0:29 y-iguchi at ak dot jp dot nec dot com
  2008-02-15  0:58 ` [Bug c++/35205] " pinskia at gcc dot gnu dot org
  2008-02-15  9:41 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: y-iguchi at ak dot jp dot nec dot com @ 2008-02-15  0:29 UTC (permalink / raw)
  To: gcc-bugs

gcc 4.1.2 compiler issues an error that 'a.x' is not a constant while I expect
'a.x' is a constant.

$ cat test.c
#include <stdio.h>

struct s{
        int i;
        enum {x};
}a;

int main(void)
{
        switch(1){
        case a.x: ;
        }
        return 0;
}
$ g++ test.c
test.c: In function 'int main()':
test.c:11: error: 'a' cannot appear in a constant-expression
test.c:11: error: `.' cannot appear in a constant-expression
$ g++ --version
g++ (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


-- 
           Summary: Structure enum wrongly interpreted as a variable in
                    switch case.
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: y-iguchi at ak dot jp dot nec dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35205


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/35205] Structure enum wrongly interpreted as a variable in switch case.
  2008-02-15  0:29 [Bug c++/35205] New: Structure enum wrongly interpreted as a variable in switch case y-iguchi at ak dot jp dot nec dot com
@ 2008-02-15  0:58 ` pinskia at gcc dot gnu dot org
  2008-02-15  9:41 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-02-15  0:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-02-15 00:57 -------
I don't think this is a bug, a here is a variable so you are accessing the enum
value via the variable which is a constant but not a constant integral
expression.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35205


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/35205] Structure enum wrongly interpreted as a variable in switch case.
  2008-02-15  0:29 [Bug c++/35205] New: Structure enum wrongly interpreted as a variable in switch case y-iguchi at ak dot jp dot nec dot com
  2008-02-15  0:58 ` [Bug c++/35205] " pinskia at gcc dot gnu dot org
@ 2008-02-15  9:41 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-15  9:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-02-15 09:40 -------
Either you want

struct s {
   int i;
   enum { x } foo;
}a;

and case a.foo:  which is indeed not a integral cosntant expression or you
simply want

case x:

which is what of course works.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35205


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-15  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-15  0:29 [Bug c++/35205] New: Structure enum wrongly interpreted as a variable in switch case y-iguchi at ak dot jp dot nec dot com
2008-02-15  0:58 ` [Bug c++/35205] " pinskia at gcc dot gnu dot org
2008-02-15  9:41 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).