This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Q. about POD with const member (or g++ vs. Comeau)
- From: Stefan Naewe <stefan dot naewe at atlas-elektronik dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 27 Jun 2008 12:41:33 +0200
- Subject: Re: Q. about POD with const member (or g++ vs. Comeau)
- References: <48649665.9090903@atlas-elektronik.com> <4864C220.1050404@redhat.com>
On 6/27/2008 12:34 PM, Andrew Haley wrote:
> Stefan Naewe wrote:
>> Given the following:
>>
>>
>> // ++ CODE
>> struct S
>> {
>> const int ci;
>> };
>>
>> int main()
>> {
>> S * s = new S;
>> }
>> // -- CODE
>>
>>
>> Comeau Online gives me:
>>
>> // ++ output
>> Comeau C/C++ 4.3.10.1 (May 29 2008 09:37:15) for ONLINE_EVALUATION_BETA1
>> Copyright 1988-2008 Comeau Computing. All rights reserved.
>> MODE:strict errors C++ C++0x_extensions
>>
>> "ComeauTest.c", line 1: warning: class "S" defines no constructor to
>> initialize the
>> following:
>> const member "S::ci"
>> struct S
>> ^
>>
>> "ComeauTest.c", line 8: error: object has an uninitialized const or
>> reference member
>> S * s = new S;
>> ^
>>
>> 1 error detected in the compilation of "ComeauTest.c".
>>
>> // -- output
>>
>>
>> Different g++ versions
>> 4.2.3
>> 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
>> gcc version 4.3.1 20080404 (prerelease) [gcc-4_3-branch revision 133917]
>> (Ubuntu 20080404-0ubuntu1)
>>
>> give:
>>
>> // ++ output
>> constmember.cc: In function 'int main()':
>> constmember.cc:8: warning: unused variable 's'
>> // -- output
>>
>>
>> Reading 5.3.4.15 (and 8.5.5) of the holy standard
>> I'd say Comeau is right, the program is ill-formed, isn't it?
>
> Yes.
'Yes'
as in
'Yes, the program is ill formed'
or
'Yes'
as in
'Yes, the program is ill formed and there's a bug in GCC'
??
> ISO/IEC 14882:1998(E)
> 12.6.2 Initializing bases and members, Para 4
>
> "If the entity is a nonstatic data member of a const-qualified type,
> the entity class shall have a user-declared default constructor."
>
> Andrew.
Thanks
Stefan
--
----------------------------------------------------------------
Dipl.-Inform. Stefan Naewe ATLAS Elektronik GmbH
Dept.: NUS T4
phone: +49-(0)421-457-1378 Sebaldsbruecker Heerstr. 235
fax: +49-(0)421-457-3913 28305 Bremen
----------------------------------------------------------------
/dev/random says: Clones are people two.