Topic: 9.2/2 Suggestion: the class should be complete within nested enumerator definitions and static data member initializers


Author: "Christopher Yeleighton" <krixel@qed.pl>
Date: Wed, 27 Jul 2005 12:35:27 CST
Raw View
Consider the following code snippet:

struct C2027 {
 static char buf[01];
 static unsigned const buf_size_1 = sizeof buf;
 static unsigned const buf_size_C2027 = sizeof static_cast<C2027 const
*>(0)->buf;
 // error C2027: use of undefined type 'C2027'
 void fun(unsigned = sizeof static_cast<C2027 const *>(0)->buf); // OK
};

According to the standard, this snippet is malformed:

"ComeauTest.c", line 4: error: pointer to incomplete class type is not
allowed
   static unsigned const buf_size_C2027 = sizeof static_cast<C2027 const
*>(0)->buf;
                                                 ^

But, except for compliance with the standard, there is no semantic
difference between the initializer of buf_size_1 and buf_size_C2027.  It is
counterintuitive.

Suggestion: change 9.2/2 to:

2 A class is considered a completely-defined object type (3.9) (or complete
type) at the closing } of the class-specifier. Within the class
member-specification, the class is regarded as complete within function
bodies, default arguments, constructor ctor-initializers, enumerator
definitions and static data member initializers (including such things in
nested classes). Otherwise it is regarded as incomplete within its own class
member-specification.

Any comments?
Chris


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]