Is a bug with Comeau or I miss something as Comeau says?

Discussion in 'C++' started by Rasmus Johansen, Oct 18, 2007.

  1. "Barry" wrote:
    > What's the point that the language constrains on this?


    The point is to avoid having an object in an indeterminate state which can't
    get out of it. What would the point of your code be? As the snippet from the
    standard clearly states the object will be in an indeterminate state because
    it's a POD-class, and since you declared it const you can't change it, so
    you'd simply have an unusable object.
     
    Rasmus Johansen, Oct 18, 2007
    #1
    1. Advertising

  2. Rasmus Johansen

    Barry Guest

    <code>
    struct A {};

    int main()
    {
    const A ca;
    }
    </code>

    <output>
    "ComeauTest.c", line 5: error: const variable "ca" requires an
    initializer -- class
    "A" has no explicitly declared default constructor
    const A ca;
    </output>

    I don't find any thing in standard to support Comeau.
    If it's a bug with Comeau, then it's quite silly.
    If I was wrong, then I was doing this wrong all the time.
     
    Barry, Oct 18, 2007
    #2
    1. Advertising

  3. Barry wrote:
    > <code>
    > struct A {};
    >
    > int main()
    > {
    > const A ca;
    > }
    > </code>
    >
    > <output>
    > "ComeauTest.c", line 5: error: const variable "ca" requires an
    > initializer -- class
    > "A" has no explicitly declared default constructor
    > const A ca;
    > </output>
    >
    > I don't find any thing in standard to support Comeau.


    Look in [dcl.init]/9.

    > If it's a bug with Comeau, then it's quite silly.
    > If I was wrong, then I was doing this wrong all the time.


    [dcl.init]/9:

    "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. Otherwise, if no initializer is
    specified for a non-static object, the object and its subobjects,
    if any, have an indeterminate initial value92); if the object or
    any of its subobjects are of const-qualified type, the program is
    ill-formed."

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 18, 2007
    #3
  4. Rasmus Johansen

    Barry Guest

    Victor Bazarov wrote:

    Thanks V,

    what if I use C structs in cxx files?

    After the inclusion of header file
    the code looks like this:

    extern "C"
    {
    struct A {};
    }

    int main()
    {
    const A ca;
    }

    But we can't change the original definition of struct A.
    So we just can't declare /ca/ of /const A/ ?

    What's the point that the language constrains on this?
     
    Barry, Oct 18, 2007
    #4
  5. Barry wrote:
    > Victor Bazarov wrote:
    >
    > Thanks V,
    >
    > what if I use C structs in cxx files?


    There is no such thing. If you mean "what if I use POD structs
    in my C++ program", then the question is legitimate. But you're
    not gonna like the answer anyway, sorry. What do you mean "what
    if you use C structs"?

    > After the inclusion of header file
    > the code looks like this:
    >
    > extern "C"
    > {
    > struct A {};
    > }
    >
    > int main()
    > {
    > const A ca;
    > }
    >
    > But we can't change the original definition of struct A.
    > So we just can't declare /ca/ of /const A/ ?
    >
    > What's the point that the language constrains on this?


    No, you just need to provide a proper initialiser:

    int main()
    {
    const A ca = {};
    }

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Oct 18, 2007
    #5
    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. youngeagle

    I miss frames!

    youngeagle, Aug 24, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    669
    Vidar Petursson
    Oct 23, 2004
  2. Wayne Wengert

    What Did I Miss?

    Wayne Wengert, May 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    457
    Wayne Wengert
    May 25, 2005
  3. Replies:
    4
    Views:
    4,762
    picals
    Oct 2, 2009
  4. Ndeye

    miss something about xslt

    Ndeye, Dec 18, 2003, in forum: XML
    Replies:
    3
    Views:
    405
    Dimitre Novatchev
    Dec 18, 2003
  5. Alan Woodland
    Replies:
    10
    Views:
    582
    Victor Bazarov
    Aug 13, 2007
Loading...

Share This Page