Topic: Protected enum in static member definition


Author: afk@ElSegundoCA.NCR.COM (Art Kaufmann)
Date: 1996/10/30
Raw View
The following code fragment illustrates a source of contention
between a compiler vendor and myself:

class foo
{ protected:
  enum { aaSize = 10 };
  static char const aa [ aaSize ];
};

char const foo::aa [ foo::aaSize ] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

The problem is that this particular compiler rejects the reference to
foo::aaSize in the definition of foo::aa as a protection violation.
Their claim is that "this is the way C++ works."  I have another compiler
that allows this construct without error.

I could find nothing in the ARM regarding this; the DWP (Section 9.5
[class.static], para 3, first sentence) allows it.  According to the
DWP, I could even leave the "foo::" off of "aaSize".

Is this, in fact, "the way C++ works?"  Did I miss something in the ARM?

--
Art Kaufmann                |
afk@ElSegundoCA.NCR.COM     |
-------------------------------------------------------------------------------
-
"... and should anyone actually read this drivel, any knowlege of your actions
will be denied by NCR Corporation"
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: jsa@edg.com (J. Stephen Adamczyk)
Date: 1996/10/31
Raw View
In article <555uv9$i3d@rap.SanDiegoCA.NCR.COM> afk@elsegundoca.ncr.com writes:
>The following code fragment illustrates a source of contention
>between a compiler vendor and myself:
>
>class foo
>{ protected:
>  enum { aaSize = 10 };
>  static char const aa [ aaSize ];
>};
>
>char const foo::aa [ foo::aaSize ] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
>
>The problem is that this particular compiler rejects the reference to
>foo::aaSize in the definition of foo::aa as a protection violation.
>Their claim is that "this is the way C++ works."  I have another compiler
>that allows this construct without error.

They are likely basing their claim on [class.protected] in the DWP, section
11.5.  The corresponding ARM section is also 11.5.  The point of this
section is that protected members can be accessed only via a derived
class.  But this restriction was intended to apply to nonstatic data members
and functions, i.e., cases where there's a specific object involved,
and not to members like enum constants.

The ARM was clear on that.  The DWP was modified a few years back to deal
with pointers to members also, and that wording change inadvertently made
the check apply to other members also.  This was corrected at the 7/95
(Monterey) X3J16/WG21 meeting (motion 2g).  Your compiler's behavior
may conform to drafts for a couple of years preceding that date.

There is still a bit of fuzziness in the latest DWP wording, because it
talks about the check applying to "protected nonstatic member"s of a class,
and an enum constant is not declared static, so it might be considered
a nonstatic member.  But the intent is clear: enum constants, like member
constants (which ARE declared static) should not be subject to this check,
and your example should be valid.

Steve Adamczyk
Edison Design Group
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]