public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17022] New: Behavior of out-of-range enums
@ 2004-08-13 22:59 igodard at pacbell dot net
  2004-08-13 23:45 ` [Bug c++/17022] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2004-08-13 22:59 UTC (permalink / raw)
  To: gcc-bugs

I'm pretty sure that the behavior of:

#include <iostream>
enum A{a,b,c};
enum B{d,e,f,g};
int main() {
    std::cerr << A(3) << ":" << B(4) << "\n";
    return 0;
    }

is implementation defined by the standard, but the actual result:

~/ootbc/members/members/sweetie/test/src$ a.out
3:0

is quite startling. Are you sure that this is what you want the implementation to define?

Ivan

-- 
           Summary: Behavior of out-of-range enums
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/17022] Behavior of out-of-range enums
  2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
@ 2004-08-13 23:45 ` pinskia at gcc dot gnu dot org
  2004-08-14  3:58 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-13 23:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-13 23:45 -------
Yes this is what we want but we should warn about this see PR 12242 for which I marking this as a dup 
of.

*** This bug has been marked as a duplicate of 12242 ***

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


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


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

* [Bug c++/17022] Behavior of out-of-range enums
  2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
  2004-08-13 23:45 ` [Bug c++/17022] " pinskia at gcc dot gnu dot org
@ 2004-08-14  3:58 ` bangerth at dealii dot org
  2004-08-14  5:23 ` igodard at pacbell dot net
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-08-14  3:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-14 03:58 -------
The size of a variable of enum type is exactly the number of bits needed 
to represent the largest member of the enum (so that you can bit-or 
elements). The result therefore makes perfect sense. 
 
W. 

-- 


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


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

* [Bug c++/17022] Behavior of out-of-range enums
  2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
  2004-08-13 23:45 ` [Bug c++/17022] " pinskia at gcc dot gnu dot org
  2004-08-14  3:58 ` bangerth at dealii dot org
@ 2004-08-14  5:23 ` igodard at pacbell dot net
  2004-08-14  6:11 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2004-08-14  5:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2004-08-14 05:23 -------
Well, the size thinh mentioned by bangaerth was what I had assumed from the behavior, but it doesn't really explain *all* the behavior. Consider:

#include <iostream>
enum A{a,b,c};
enum B{d,e,f,g};
int main() {
    int three = 3;
    int four = 4;
    std::cerr << A(three) << ":" << A(3) << "!" << B(four) <<":" << B(4) << "\n"
;
    return 0;
    }

That gets you:

~/ootbc/members/members/sweetie/test/src$ a.out
3:3!4:0

So I have re-opened this as a bug, in that the constant-expression result is not the same as the run-time result. This seems to call for more than a warning, even if it is implementation-defined.

Ivan

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


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


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

* [Bug c++/17022] Behavior of out-of-range enums
  2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2004-08-14  5:23 ` igodard at pacbell dot net
@ 2004-08-14  6:11 ` pinskia at gcc dot gnu dot org
  2004-08-14  6:16 ` pinskia at gcc dot gnu dot org
  2004-08-14 11:51 ` igodard at pacbell dot net
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-14  6:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-14 06:11 -------
Actually it is not undefined or implementation defined by the standard, it is unspecified which is a 
totally different ball game and we just define it as constants do the get anded, likewise with 
optimization where you can prove that the variable is a constant.  Otherwise it is the same value as 
before this change.

See: <http://www.devx.com/tips/Tip/12684> for unspecified vs. undefined
Also see PR 15330 where we defined the defintion of what we want to be able to do which I am going 
to mark as a dup of.

*** This bug has been marked as a duplicate of 15330 ***

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


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


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

* [Bug c++/17022] Behavior of out-of-range enums
  2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2004-08-14  6:11 ` pinskia at gcc dot gnu dot org
@ 2004-08-14  6:16 ` pinskia at gcc dot gnu dot org
  2004-08-14 11:51 ` igodard at pacbell dot net
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-14  6:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-14 06:15 -------
Oh by the way, we don't have to document unspecified behavior, ref: <http://www.embedded.com/
shared/printableArticle.jhtml?articleID=9900563>.  This is constrast to implementation defined 
behavior.

-- 


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


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

* [Bug c++/17022] Behavior of out-of-range enums
  2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
                   ` (4 preceding siblings ...)
  2004-08-14  6:16 ` pinskia at gcc dot gnu dot org
@ 2004-08-14 11:51 ` igodard at pacbell dot net
  5 siblings, 0 replies; 7+ messages in thread
From: igodard at pacbell dot net @ 2004-08-14 11:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2004-08-14 11:51 -------
How about at least a warning when you wrap around a constant-expression? For that matter, if it's unspecified can you specify it as an error?

Ivan

-- 


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


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

end of thread, other threads:[~2004-08-14 11:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-13 22:59 [Bug c++/17022] New: Behavior of out-of-range enums igodard at pacbell dot net
2004-08-13 23:45 ` [Bug c++/17022] " pinskia at gcc dot gnu dot org
2004-08-14  3:58 ` bangerth at dealii dot org
2004-08-14  5:23 ` igodard at pacbell dot net
2004-08-14  6:11 ` pinskia at gcc dot gnu dot org
2004-08-14  6:16 ` pinskia at gcc dot gnu dot org
2004-08-14 11:51 ` igodard at pacbell dot net

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