Topic: ANSI C++ Standard Problem


Author: Oliver Herrmann VS/EFB F108/u/5 #46178 <O.Herrmann@alcatel.de>
Date: 1998/10/28
Raw View
Hi all,

I have a problem with the follwing code:

class A
{
  private:
    int myInt;

  public:
    A& operator = (int right) {myInt = right; return *this;}
};

union B
{
    char f1;
    A    f2;
};

The GNU Compilers 2.7.2 and 2.8.1 exit with the error-message

   member `class A B::f2' with assignment operator not allowed in union

The Draft Standard says in chapter "9.5 Unions ":

An object of a class with a  non-trivial default  constructor
(_class.ctor_),  a  non-trivial copy constructor (_class.copy_), a
non-trivial destructor (_class.dtor_),  or  a  non-trivial  copy
assignment operator (_over.ass_, _class.copy_) cannot be a member of a
union, nor can an array of such  objects.

But my assignment operator is not a COPY assignment operator. In chapter
"13.5.3 Assignment" they distinguish between assignment and copy
assignment operators.

   X& X::operator= (const X&)   Copy Assignment Operator
   X& X::operator= (int)        Assignment Operator

Some other compilers had no problems with the example. So in my opinion
the GNU Compiler is not standard conform. Can you please give some
feedback if I am right or not ?

Thanks

   Oliver

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ 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              ]





Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/10/28
Raw View
Oliver Herrmann VS/EFB F108/u/5 #46178 <O.Herrmann@alcatel.de> wrote:
>struct A
>  { int myInt; A& operator = (int right) {myInt = right; return *this;} };
>union B { char f1; A f2; };
>
>The GNU Compilers 2.7.2 and 2.8.1 exit with the error-message
>   member `class A B::f2' with assignment operator not allowed in union
>
>Some other compilers had no problems with the example. So in my opinion
>the GNU Compiler is not standard conform. Can you please give some
>feedback if I am right or not ?

The Gnu compilers are wrong, here.

Generally, Egcs-1.x is a better choice than Gcc-2.8.x, among Gnu
compilers, because the 2.8.x development line is dead.  However,
in this case Egcs-1.1 is wrong too.

The EDG-based compilers I have get it right.

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/



[ 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              ]