Boost logo

Boost :

From: Boris Gubenko (Boris.Gubenko_at_[hidden])
Date: 2006-03-13 15:14:46


The compiler is correct. Instead of quoting C++ Standard, I'll quote
Lippman C++ Primer, 3rd edition, p.113:

  An object of an enumeration type can be be initialized and
  assigned only with another object of the same enumeration
  type or with one of its set of enumerators. For example,
  although 3 is a legal value associated with Points, it cannot
  be explicitly assigned to a Points object:
[...]
  enum Points { point2d = 2, point2w, point3d = 3, point3w };
  // error: pt2w initialized with int
  Points pt2w = 3;

Btw, you'd get the same compilation error with any EDG-based
compiler. On Tru64, for example:

$ cxx -V
Compaq C++ V6.5-042 for Compaq Tru64 UNIX V5.0A (Rev. 1094)
Compiler Driver V6.5-042 (cxx) cxx Driver
$ cxx -c enum_init.cpp
cxx: Error: enum_init.cpp, line 11: a value of type "int" cannot be
          used to
          initialize an entity of type "udt_builtin_mixture_enum"
  udt_builtin_mixture_enum value2 = 0; // this doesn't
------------------------------------^
cxx: Info: 1 error detected in the compilation of "enum_init.cpp".
$

Or on VMS:

$ cxx/ver
Compaq C++ V6.5-004 for OpenVMS Alpha V7.3-2
$ cxx/noobj enum_init.cpp

  udt_builtin_mixture_enum value2 = 0; // this doesn't
....................................^
%CXX-E-BADINITTYP, a value of type "int" cannot be used to initialize
          an entity of type "udt_builtin_mixture_enum"
at line number 11 in file WORK5:[BORIS]ENUM_INIT.CPP;1

Boris

----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, March 13, 2006 2:11 PM
Subject: [boost] HP-UX aCC or boost problem?

> While trying to port Boost.Python to HP-UX using the native "aCC" compiler
> I
> ran into this issue:
>
> void foo()
> {
> enum udt_builtin_mixture_enum
> {
> builtin_to_builtin
> ,builtin_to_udt
> ,udt_to_builtin
> ,udt_to_udt
> } ;
> udt_builtin_mixture_enum value1 = builtin_to_builtin; // this works
> udt_builtin_mixture_enum value2 = 0; // this doesn't
> }
>
>
> % aCC -AA -c enum_init.cpp
> "enum_init.cpp", line 11: error #2144: a value of type "int" cannot be
> used to
> initialize an entity of type "udt_builtin_mixture_enum"
> udt_builtin_mixture_enum value2 = 0;
> ^
>
> 1 error detected in the compilation of "enum_init.cpp".
>
>
> Is the compiler correct in rejecting the initialization with 0?
>
> Thanks!
>
> Cheers,
> Ralf
>
> P.S.: aCC: HP aC++/ANSI C B3910B A.06.01 [Jan 05 2005]
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk