From -4184388419288111786
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,11af4794c44339e8
X-Google-Attributes: gidf78e5,public
From: "Bill Wade" <bill.wade@stoner.com>
Subject: Re: Can you static_cast between enums?
Date: 1999/12/07
Message-ID: <82joi7$o4k@library2.airnews.net>#1/1
X-Deja-AN: 557843652
X-NNTP-Posting-Host: !aq6<1k-Vc7Io(G (Encoded at Airnews!)
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <ktA14.377$6A5.16841@dfiatx1-snr1.gtei.net>
X-UID: 0000000001
X-Status: $$$T
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Neosoft (using Airnews.net!)
Abuse-Reports-To: abuse at airmail.net to report improper postings
Newsgroups: comp.std.c++
Originator: clamage@taumet



Ron Burk wrote in message ...
>enum Type1 {value1, value2};
>enum Type2 {value3, value4};

> [ are the following legal? ]
> static_cast<Type2>(value1);
> Type2 t(value1);

I'm pretty sure the static_cast is legal.  There is an implicit promotion
from value1 to some integral type (4.5/2) and static_cast  converts any
integral type to any enum type (5.2.9/7).

I believe the second is illegal.  The applicable part of the standard is the
last "Otherwise" of 8.5/14, at the bottom of page 143:

"... standard conversions will be used to convert [value1 to Type2].  If the
conversion cannot be done, the initialization is ill-formed."

HTH




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




