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

D

DarkSpy

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
 
T

Thaddeus L Olczyk

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.
 
T

tom_usenet

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
 
D

DarkSpy

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...
 
T

tom_usenet

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top