Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to report bug to g++ ? got a bug and fixed up source code

Reply
Thread Tools

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

 
 
DarkSpy
Guest
Posts: n/a
 
      06-26-2003
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
 
Reply With Quote
 
 
 
 
Thaddeus L Olczyk
Guest
Posts: n/a
 
      06-26-2003
On 26 Jun 2003 00:47:32 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      06-26-2003
On 26 Jun 2003 00:47:32 -0700, (E-Mail Removed) (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
 
Reply With Quote
 
DarkSpy
Guest
Posts: n/a
 
      06-27-2003
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...
 
Reply With Quote
 
tom_usenet
Guest
Posts: n/a
 
      06-27-2003
On 26 Jun 2003 18:29:05 -0700, (E-Mail Removed) (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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Best way to report progress at fixed intervals Slaunger Python 13 12-10-2008 05:21 PM
If you Got Questions? I bet We got Answers Leisure.201@gmail.com Javascript 1 04-28-2007 11:04 PM
Free Fixed-Width/Fixed-Pitch fonts? johnp HTML 4 05-23-2005 06:14 AM
Got may Norton AntiSpam problem fixed Vic Computer Support 0 05-09-2004 02:00 AM



Advertisments