473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Jul 19 '05 #1
4 2092
On 26 Jun 2003 00:47:32 -0700, co****@21cn.com (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.
Jul 19 '05 #2
On 26 Jun 2003 00:47:32 -0700, co****@21cn.com (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
Jul 19 '05 #3
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...
Jul 19 '05 #4
On 26 Jun 2003 18:29:05 -0700, co****@21cn.com (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 isan 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
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nothing | last post by:
I have a report based on a query that is based agaisnt two tables. The report pulls information for 1 customer. The tables may hold multipul customers. I want to email just the ONE report. All...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
9
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want...
5
by: bcanavan | last post by:
When I export xml(and xls) from Access 2003 the result is a complete report in a single page. I would like to get the entire report in a single page (one trip to the server) for printing and...
3
by: Chris Botha | last post by:
I have a Report Viewer control on a Web page. I want the control to size automatically as the Web page sizes, so I've set the control's width property to 90% and the height property to 90% as well....
1
by: Brad | last post by:
Thanks for taking the time to read my question. I have a table of data that has Date, Data and Category. I need to show, in a report, each Categories Data by Date. The Date has to be it's own...
1
by: steve | last post by:
Hi All Can anybody point me to some info on creating a graph in VB.net 2005 report viewer I can't seem to find any on the web I want to show sales totals by week in a vertical bar graph ...
8
by: Ryan | last post by:
Hello, I'm new to Access and DB's in general. I've taken over some light duty support for a lab information system we use in house. Most of our dates are reported as "10/31/2006 12:30:00 PM"...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
11
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.