Q. about POD with const member (or g++ vs. Comeau)

Discussion in 'C++' started by Stefan Naewe, Jun 25, 2008.

  1. Stefan Naewe

    Stefan Naewe Guest

    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


    Two different g++ versions (4.2.3 and "4.1.2 20061115 (prerelease) (Debian
    4.1.1-21)" give me:

    // ++ 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?

    What about g++ ? Can anyone test this with the latest g++ (4.3.1), please ?

    Regards
    Stefan
    --
    Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    Plain text mails only, please http://www.expita.com/nomime.html
     
    Stefan Naewe, Jun 25, 2008
    #1
    1. Advertising

  2. Stefan Naewe

    gpderetta Guest

    On Jun 25, 12:44 pm, 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
    >
    > Two different g++ versions (4.2.3 and "4.1.2 20061115 (prerelease) (Debian
    > 4.1.1-21)" give me:
    >
    > // ++ 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?
    >
    > What about g++ ? Can anyone test this with the latest g++ (4.3.1), please ?
    >


    gcc version 4.3.1 20080404 (prerelease) [gcc-4_3-branch revision
    133917] (Ubuntu 20080404-0ubuntu1)

    test.cc: In function 'int main()':
    test.cc:9: warning: unused variable 's'

    same warning. No hard error.

    HTH,

    --
    gpd
     
    gpderetta, Jun 25, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajax Chelsea

    Is array of POD still a POD type?

    Ajax Chelsea, Dec 1, 2003, in forum: C++
    Replies:
    1
    Views:
    345
    Ron Natalie
    Dec 1, 2003
  2. Javier
    Replies:
    2
    Views:
    565
    James Kanze
    Sep 4, 2007
  3. Rasmus Johansen
    Replies:
    4
    Views:
    380
    Victor Bazarov
    Oct 18, 2007
  4. fungus
    Replies:
    13
    Views:
    891
    fungus
    Oct 31, 2008
  5. Himanshu Garg
    Replies:
    1
    Views:
    165
    Himanshu Garg
    Sep 21, 2003
Loading...

Share This Page