Possible Additional g++ bug(s)

Peri Saner peri@saner.net
Sun Apr 18 04:31:00 GMT 2004


Hello,

I am a newbie, so if this email was sent to the wrong address, please
forgive me and pass it along to those handling bugs for the gnu compiler.
Thanks.

I was getting compiler errors due to having only constructors with default
arguments. In other words, objects with no initialization arguments were
causing trouble. After some search, I was relieved to find an explanation
to the trouble I was having with object initialization. I found the
following paragraph on http://gcc.gnu.org/gcc-3.2/changes.html:

>The C++ compiler does not correctly zero-initialize pointers-to-data
>members. You must explicitly initialize them. For example: int S::*m(0);
>will work, but depending on default-initialization to zero will not work.
>This bug cannot be fixed in GCC 3.2 without inducing unacceptable risks.
>It will be fixed in GCC 3.3.

I would like to point out that I am having the difficulty with object
initialization. Objects that are not explicitly initialized will cause the
compiler to barf. This occured when the default constructor has one
default argument and there is no constructor with 0 default arguments:

>% make
>g++ -Wall -c Fraction.cpp
>++ -Wall -c test-Fraction.cpp
>test-Fraction.cpp: In function `int main()':
>test-Fraction.cpp:24: no matching function for call to
>`Fraction::Fraction()'
>Fraction.H:45: candidates are: Fraction::Fraction(const Fraction&)
>Fraction.H:42:                 Fraction::Fraction(int, int)
>Fraction.H:35:                 Fraction::Fraction(int)
>test-Fraction.cpp:24: no matching function for call to
>`Fraction::Fraction()'
>Fraction.H:45: candidates are: Fraction::Fraction(const Fraction&)
>Fraction.H:42:                 Fraction::Fraction(int, int)
>Fraction.H:35:                 Fraction::Fraction(int)
>make: *** [test-Fraction.o] Error 1

This was the second error I discovered with the compiler. The first error
led me to the error above after I found the "bandaid fix."

Here is my description of the first bug I found:

There was a discrepancy between my class definition file and my function
definition file. Here is the message:

>% make
>g++ -Wall -c Fraction.cpp
>Fraction.cpp:22: default argument given for parameter 1 of `
>   Fraction::Fraction(int = 1)'
>Fraction.H:35: after previous specification in `Fraction::Fraction(int =
1)'
>make: *** [Fraction.o] Error 1

After consulting many sources, I determined that the only way to get it to
compile was to put the following declaration in the class definition, file
Fraction.H:

        Fraction( int );

With an actual value given to it in the function definition file,
Fraction.cpp.

According to the C++ standards I have read, the following declarations
should be allowed in both the header file class definition and the
function definition:

	Fraction( int n = 0 );
	Fraction( int = 0 );

And should not cause any compiler confusion. In addition, the two
declarations listed above do work in the program compiled on an earlier
version of g++. Imagine my surprise when I ported the program home to a
newly updated Linux box and it wouldn't compile. Oy.

Please feel free to contact me if I have failed to explain the problem(s)
clearly. In summary, I believe that one should be able to put the default
values in both the class definition function declaration, and the
definition of the function.

Thank you for your attention.

Sincerely,

Peri Saner

*********************************************************
Peri Saner
1749 S. Yale St.
Wichita, KS  67218-4017
(316) 640-8542
peri@saner.net
http://peri.saner.net



More information about the Gcc mailing list