how to report bug to g++ ? got a bug and fixed up source code

Discussion in 'C++' started by DarkSpy, Jun 26, 2003.

  1. DarkSpy

    DarkSpy Guest

    g++ 3.2.x and g++ 3.3 have this bug:

    class A{};

    main()
    {
    sizeof(A());
    }
    got error message: ISO C++ forbids applying `sizeof' to a function type

    fixed up code

    template <typename T>
    struct __sizeof
    {
    operator T() const { return T(); }
    operator int() const { return sizeof(operator T()); }
    };

    usage: __sizeof<A>();

    this bug is already occur in g++ 3.3
    DarkSpy, Jun 26, 2003
    #1
    1. Advertising

  2. On 26 Jun 2003 00:47:32 -0700, (DarkSpy) wrote:

    >g++ 3.2.x and g++ 3.3 have this bug:
    >
    >class A{};
    >
    >main()
    >{
    > sizeof(A());
    >}
    >got error message: ISO C++ forbids applying `sizeof' to a function type

    The only bug here is the one that crawled into your brain and ate it.
    Next time, before you go around blaming the compiler for your
    stupidity, learn the language.
    --------------------------------------------------
    Thaddeus L. Olczyk, PhD
    Think twice, code once.
    Thaddeus L Olczyk, Jun 26, 2003
    #2
    1. Advertising

  3. DarkSpy

    tom_usenet Guest

    On 26 Jun 2003 00:47:32 -0700, (DarkSpy) wrote:

    >g++ 3.2.x and g++ 3.3 have this bug:
    >
    >class A{};
    >
    >main()
    >{
    > sizeof(A());
    >}
    >got error message: ISO C++ forbids applying `sizeof' to a function type


    Yes, the error is correct. A() is a function type (a function
    returning an A and taking no parameters) and you can't apply sizeof to
    function types. The paretheses around the A() mean that it checks for
    A() being a type-id, before it checks to see whether (A()) is an
    expression. Most people seem to think that you need () around a sizeof
    expression, and this leads to these false "bug"s.

    I think you meant to write:

    sizeof A();

    Tom
    tom_usenet, Jun 26, 2003
    #3
  4. DarkSpy

    DarkSpy Guest

    thanks to above.

    but i think the A() is a temporary object, the g++ may judgement it is
    an object not a function.

    i using intel C++ 7.1 to compiling this code, the result is
    correct.......


    thanx anyway...
    DarkSpy, Jun 27, 2003
    #4
  5. DarkSpy

    tom_usenet Guest

    On 26 Jun 2003 18:29:05 -0700, (DarkSpy) wrote:

    >thanks to above.
    >
    >but i think the A() is a temporary object,


    A() is a temporary object is the context of an expression, but it is
    the type of a function taking no arguments and returning an A is the
    context of a type-id.

    the g++ may judgement it is
    >an object not a function.


    It will obviously consider it a temporary in the context of an
    expression.

    For another example, try this:

    class A{};
    int main()
    {
    A a(A());
    sizeof(a);
    }

    "a" above isn't an object at all (you might expect it to be a copy of
    a temporary default constructed A), but the declaration of a function
    that returns an A, and takes a function pointer parameter that is a
    pointer to function taking no arguments and returning an A. Hence the
    sizeof call is an error, since a is a function.

    >i using intel C++ 7.1 to compiling this code, the result is
    >correct.......


    No, intel C++ 7.1 is wrong according to the C++ standard. G++ and
    Comeau C++ diagnose the error correctly.

    The fact that it is an error is obvious from the standard (my emphasis
    added):

    1 The sizeof operator yields the number of bytes in the object
    representation of its operand. The operand
    is either an expression, which is not evaluated, or a **parenthesized
    type­id**. The sizeof operator shall not
    be applied to an expression that has function or incomplete type, or
    to an enumeration type before all its
    enumerators have been declared, or to **the parenthesized name of such
    types**, or to an lvalue that designates
    a bit­field.

    In your case you are applying sizeof to the parenthesized name of a
    function type, which is illegal.

    Tom
    tom_usenet, Jun 27, 2003
    #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. James Wallace
    Replies:
    0
    Views:
    1,039
    James Wallace
    Oct 17, 2003
  2. johnp
    Replies:
    4
    Views:
    3,655
    Toby Inkster
    May 23, 2005
  3. =?Utf-8?B?bG9kYXRva2Fi?=

    Got error CS0433 for Crystal Report on Windows 2000 Server

    =?Utf-8?B?bG9kYXRva2Fi?=, Aug 1, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,469
    Steven Cheng[MSFT]
    Aug 2, 2006
  4. Slaunger
    Replies:
    13
    Views:
    435
    George Sakkis
    Dec 10, 2008
  5. Ashish Mehndi
    Replies:
    0
    Views:
    1,149
    Ashish Mehndi
    Aug 2, 2004
Loading...

Share This Page