This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/2189: g++ rejects legal code
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/2189: g++ rejects legal code
- From: mayer at tux dot org
- Date: Mon, 5 Mar 2001 13:57:24 -0800
- Cc: mayer at tux dot org
- Reply-To: mayer at tux dot org
>Number: 2189
>Category: c++
>Synopsis: g++ rejects legal code
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon Mar 05 14:06:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Uwe F. Mayer
>Release: 2.97 20010205 (experimental)
>Organization:
tux.org
>Environment:
System: Linux tosca 2.2.18 #1 Sun Feb 25 14:33:05 PST 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-20010205/configure --prefix=/usr/local/gcc --disable-nls
>Description:
g++ rejects the following legal code (file bug3.cc), which has a
constructor initializer with default value and a declaration of this
constructor without the default value. The default value is the provided
in the definition. The file bug3.cc:
//#include <iostream>
//using namespace std;
class Z {
public:
// gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) allows to
// write Z(int) while gcc version 2.97 20010205 wants Z(int j=43)
Z(int);
//void print ();
private:
int i;
};
Z::Z(int j=43): i(j){}
//void Z::print(void){ cout << "Z : i= " << i << ".\n";}
int main()
{
Z zobject=Z();
//zobject.print();
}
>How-To-Repeat:
Run "g++ bug3.cc". I get:
bug3.cc: In function `int main()':
bug3.cc:17: no matching function for call to `Z::Z()'
bug3.cc:3: candidates are: Z::Z(const Z&)
bug3.cc:12: Z::Z(int)
Please note that an earlier version of g++ accepted this code. I do not
know whether this behavior change of g++ was planned due to adherence to
some new standard. If so, please forget about this bug report.
Here is bug3.ii, just in case it is a bug:
# 3 "bug3.cc"
class Z {
public:
Z(int);
private:
int i;
};
Z::Z(int j=43): i(j){}
int main()
{
Z zobject=Z();
}
>Fix:
Provide the default value in the declaration. For the example above, that
amounts to writing:
class Z {
public:
Z(int j=43);
private:
int i;
};
Z::Z(int j=43): i(j){};
>Release-Note:
>Audit-Trail:
>Unformatted: