This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Legal c++ one-liner doesn't compile with gcc 2.95.2


> This is derived from code by Scott Meyers -
> 
> ------------------
> const class { } a;
> ------------------
> 
> g++ reports
> 
> 1: uninitialized const `a'

Thanks for your bug report. I believe this is not a bug in g++, but in
your program, 8.5/9 says

# If no initializer is specified for an object, and the object is of
# (possibly cv­qualified) non­POD class type (or array thereof), the
# object shall be default­initialized; if the object is of
# const­qualified type, the underlying class type shall have a
# user­declared default constructor.

I'm not exactly sure how to read this, to me, it reads as

If no initializer is specified (NIIS) and if the object is of
const-qualified type (OOCQT) , then the class type shall have a
user-declared default constructor (SHUDDC)

- which this class doesn't have, so the program ill-formed.

Perhaps its intended meaning is

If NIIS and the object is of non-POD class type and OOCQT, then SHUDDC.

In this case, one of the preconditions would not hold, so the rest of
8.5/9 would apply

# Otherwise, if no initializer is specified for an object, the object
# and its subobjects, if any, have an indeterminate initial value; if
# the object or any of its subobjects are of const­qualified type, the
# program is ill­formed.

No initializer is specified, and the object is of const-qualified
type, so the program is ill-formed.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]